50 lines
1.8 KiB
Python
Executable File
50 lines
1.8 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
import subprocess
|
|
import os
|
|
import re
|
|
import yaml
|
|
|
|
def getRsyncCommandAsList(source, destination, exclude, dry = True):
|
|
rsyncCommandList = ['rsync', '-avi', source, destination, '--delete']
|
|
rsyncCommandList.extend(exclude)
|
|
if dry:
|
|
rsyncCommandList.append('-n')
|
|
return rsyncCommandList
|
|
|
|
def syncDisks(source, destination):
|
|
if os.path.ismount(destination['path']):
|
|
print(colors.BLUE + 'Próbna synchronizacja dysków ' + source['label'] + ' i ' + destination['label'] + colors.END)
|
|
subprocess.run(getRsyncCommandAsList(source['path'], destination['path'], exclude))
|
|
if (re.match('^[tT]$', input(colors.ORANGE + 'Czy wynik jest spodziewany i pożądany? [t/N]' + colors.END))):
|
|
subprocess.run(getRsyncCommandAsList(source['path'], destination['path'], exclude, False))
|
|
print(colors.GREEN + 'Zakończono synchronizację dysków ' + source['label'] + ' i ' + destination['label'] + colors.END)
|
|
else:
|
|
print(colors.RED + 'Pomijam synchronizację dysków ' + source['label'] + ' i ' + destination['label'] + colors.END)
|
|
else:
|
|
print('Nie wykryto dysku ' + destination['label'])
|
|
|
|
class colors:
|
|
BLUE = '\033[1;36m'
|
|
RED = '\033[1;31m'
|
|
GREEN = '\033[1;32m'
|
|
ORANGE = '\033[1;33m'
|
|
# BLUE = '\033[0;36m' # normal font (1 is bold)
|
|
END = '\033[m'
|
|
|
|
absPath = os.path.dirname(os.path.abspath(__file__))
|
|
|
|
|
|
with open(absPath + os.sep + 'backup-disk-config.yaml', 'r') as configFile:
|
|
config = yaml.safe_load(configFile)
|
|
configFile.close()
|
|
|
|
main = config['disks']['main']
|
|
copies = config['disks']['copies']
|
|
filesToExclude = config['files']['exclude']
|
|
|
|
exclude = list(map(lambda item: '--exclude=' + item, filesToExclude))
|
|
|
|
for disk in copies:
|
|
syncDisks(main, disk)
|