Created
May 18, 2015 00:07
-
-
Save ariscop/e1d04bb7ddabfb5e773b to your computer and use it in GitHub Desktop.
Trivial utils for managing snapshots
This file contains 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/python3 | |
from os import listdir | |
from os.path import isdir | |
from dateutil.parser import parse as parse_time | |
from datetime import datetime, timedelta | |
from collections import namedtuple | |
import pytz | |
from subprocess import call | |
earlierthan = datetime.utcnow().replace(tzinfo=pytz.UTC) - timedelta(days=1) | |
for path in listdir("./"): | |
if isdir(path): | |
time, bootid, uptime = path.split("$") | |
time = parse_time(time) | |
if(time < earlierthan): | |
call(["/sbin/btrfs", "subvol", "delete", path]) |
This file contains 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
[Unit] | |
Description=Create snapshot | |
[Service] | |
Type=oneshot | |
WorkingDirectory=/var/snapshots | |
ExecStart=/usr/local/bin/clear_snapshot | |
ExecStart=/usr/local/bin/take_snapshot %b |
This file contains 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
[Unit] | |
Description=Trigger snapshots | |
[Timer] | |
Persistent=true | |
OnBootSec=5min | |
OnUnitActiveSec=3h | |
[Install] | |
WantedBy=multi-user.target |
This file contains 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 | |
/sbin/btrfs subvolume snapshot -r / /var/snapshots/"`date -Iseconds`\$$1\$`cat /proc/uptime | cut -d\ -f1`" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment