diff options
| author | Timo Wilken | 2016-01-27 15:36:22 +0000 |
|---|---|---|
| committer | Timo Wilken | 2016-01-27 15:36:22 +0000 |
| commit | 22d8779b2f439bd105a13038dceb4c2d02cdf500 (patch) | |
| tree | d0444882987d5491edcae420939e1dea2095cb4c | |
| parent | 6b3524720642a69e068048a339abdbf08ba19e6a (diff) | |
| -rwxr-xr-x | backup.py | 27 |
1 files changed, 10 insertions, 17 deletions
@@ -15,25 +15,18 @@ def main(): """The backup script's main entry point.""" backup_time = datetime.datetime.utcnow().strftime('%Y-%m-%d/%H%M') time_folder = os.path.join(BACKUP_ROOT, backup_time) - with open(CONFIG_FILE, 'rt') as cfg_f: - tldirs = [line.strip('\n') for line in cfg_f + with open(CONFIG_FILE, 'rt') as cfg_file: + tldirs = [line.strip('\n') for line in cfg_file if not re.match(r'^\s*#', line)] for tldir in tldirs: - tlbasename = os.path.join(time_folder, os.path.basename(tldir)) - for dirpath, _, filenames in os.walk(tldir): - backup_path = os.path.join(time_folder, tlbasename, - os.path.relpath(dirpath, start=tldir)) - os.makedirs(backup_path, exist_ok=True) - for fname in filenames: - orig_fname = os.path.join(dirpath, fname) - backup_fname = os.path.join(backup_path, fname) - bak_cmd = ['zbackup', '--non-encrypted', '--silent', 'backup', - backup_fname] - with open(orig_fname, mode='rb') as orig_file: - process = subprocess.run(bak_cmd, stdin=orig_file) - if process.returncode: - print(' '.join(bak_cmd), ' failed with code ', - process.returncode, file=sys.stderr) + tar_name = os.path.join(time_folder, os.path.basename(tldir)) + '.tar' + tar_proc = subprocess.run(['tar', '-c', tldir], stdout=subprocess.PIPE) + bak_proc = subprocess.run(['zbackup', '--non-encrypted', '--silent', + 'backup', tar_name], stdin=tar_proc.stdout) + tar_proc.stdout.close() + if bak_proc.returncode: + print('zbackup (', tldir, ' -> ', tar_name, ') failed with code ', + bak_proc.returncode, file=sys.stderr) if __name__ == '__main__': |
