Skip to content

Instantly share code, notes, and snippets.

@codemicro
Created February 7, 2022 20:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codemicro/7bdc6df50de58fdf57752458f0516cd4 to your computer and use it in GitHub Desktop.
Save codemicro/7bdc6df50de58fdf57752458f0516cd4 to your computer and use it in GitHub Desktop.
Basic rclone-based backup solution
import subprocess
import os
import datetime
import json
datestring = datetime.datetime.now(datetime.timezone.utc).strftime("%Y-%m-%d_%Hh%Mm")
filename = f"server_{datestring}.tar.gz"
to_backup = None
with open(os.path.join(os.path.expandvars("$HOME"), "backupConfig.json")) as f:
to_backup = json.load(f)
subprocess.run(['tar', '-czvf', filename,] + to_backup)
subprocess.run(['rclone', 'copy', "-v", filename, 'gd:/server'])
os.remove(filename)
subprocess.run(['rclone', 'delete', "-v", '--min-age', '15d', 'gd:/server'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment