Initial commit
This commit is contained in:
Executable
+49
@@ -0,0 +1,49 @@
|
||||
#!/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)
|
||||
@@ -0,0 +1,19 @@
|
||||
disks:
|
||||
main:
|
||||
path: /path/to/main/disk
|
||||
label: label-of-main-disk
|
||||
|
||||
# can be multiple disks or just one
|
||||
copies:
|
||||
- path: /path/to/copy1/disk
|
||||
label: label-of-copy1-disk
|
||||
|
||||
- path: /path/to/copy2/disk
|
||||
label: label-of-copy2-disk
|
||||
|
||||
|
||||
files:
|
||||
# All rules of rsync --exclude applies
|
||||
exclude:
|
||||
- /as/in/rsync/exclude
|
||||
- /can/be/multiple/files/or/directories
|
||||
Reference in New Issue
Block a user