summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xbackup.py27
1 files changed, 10 insertions, 17 deletions
diff --git a/backup.py b/backup.py
index ca32cba..4e054cc 100755
--- a/backup.py
+++ b/backup.py
@@ -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__':