Skip to content

Instantly share code, notes, and snippets.

@swenson
Created August 12, 2015 05:17
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save swenson/791f147b4ea6eb7123d1 to your computer and use it in GitHub Desktop.
Save swenson/791f147b4ea6eb7123d1 to your computer and use it in GitHub Desktop.
Install tarsnap. Then, here's some stuff.
#!/bin/bash
NAME="something"
d=$(date "+%F--%H-%M-%S")
/usr/local/bin/tarsnap -c --keyfile /root/tarsnap.key --cachedir /usr/local/tarsnap-cache -f $NAME-backup-$d /etc /home /root /var
0 0 * * * /root/backup.sh > /dev/null 2>&1
30 0 * * * /root/prune.py > /dev/null 2>&1
#!/usr/bin/env python
name = "something"
import datetime
import subprocess
def exc(cmd):
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
stdout, stderr = p.communicate()
if p.returncode != 0:
raise Exception("Command failed with " + stderr)
return stdout
backups = exc('/usr/local/bin/tarsnap --keyfile /root/tarsnap.key --list-archives').strip().split('\n')
backups.sort()
backups = backups[:-10]
month_ago = name + "-" + (datetime.datetime.now() - datetime.timedelta(days=30)).strftime("backup-%F--%H-%M-%S")
for backup in backups:
if backup < month_ago:
print "Deleting", backup
exc('/usr/local/bin/tarsnap --keyfile /root/tarsnap.key --cachedir /usr/local/tarsnap-cache -d -f ' + backup)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment