Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.