Skip to content

Instantly share code, notes, and snippets.

@ariscop
Created May 18, 2015 00:07
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 ariscop/e1d04bb7ddabfb5e773b to your computer and use it in GitHub Desktop.
Save ariscop/e1d04bb7ddabfb5e773b to your computer and use it in GitHub Desktop.
Trivial utils for managing snapshots
#!/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])
[Unit]
Description=Create snapshot
[Service]
Type=oneshot
WorkingDirectory=/var/snapshots
ExecStart=/usr/local/bin/clear_snapshot
ExecStart=/usr/local/bin/take_snapshot %b
[Unit]
Description=Trigger snapshots
[Timer]
Persistent=true
OnBootSec=5min
OnUnitActiveSec=3h
[Install]
WantedBy=multi-user.target
#!/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