Created
August 12, 2015 05:17
-
-
Save swenson/791f147b4ea6eb7123d1 to your computer and use it in GitHub Desktop.
Install tarsnap. Then, here's some stuff.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
0 0 * * * /root/backup.sh > /dev/null 2>&1 | |
30 0 * * * /root/prune.py > /dev/null 2>&1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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