From a88d09bdb38feef80890a01e37e828c2cd9a01b1 Mon Sep 17 00:00:00 2001 From: "D. Joe" Date: Thu, 7 Feb 2019 20:24:38 -0500 Subject: [PATCH] Inaugural public version, suitable for mass ridicule or pity. --- COPYING | 5 +++++ README.md | 14 +++++++++++++ snap-and-rotate | 55 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+) create mode 100644 COPYING create mode 100644 README.md create mode 100755 snap-and-rotate diff --git a/COPYING b/COPYING new file mode 100644 index 0000000..06f8613 --- /dev/null +++ b/COPYING @@ -0,0 +1,5 @@ + +Copyright D. Joe Anderson 2019 + +Available for use under GPL version 2 or any later GPL version. + diff --git a/README.md b/README.md new file mode 100644 index 0000000..435bb7f --- /dev/null +++ b/README.md @@ -0,0 +1,14 @@ + +# Snap and rotate + +## Crude rotating rsync-based backup + +This will probably destroy your data horribly so please use with caution. + +I'm so behind-the-times I run it with cron. + +[Mike Rubel was inspirational](http://mikerubel.org/computers/rsync_snapshots/) +in his description of using rsync for backups. + +He is not to blame for my poorly-considered implementation. + diff --git a/snap-and-rotate b/snap-and-rotate new file mode 100755 index 0000000..0df9d70 --- /dev/null +++ b/snap-and-rotate @@ -0,0 +1,55 @@ +#!/bin/bash + +# Log the start + +/usr/bin/logger Starting snap-and-rotate + +# I start an ssh-agent, hand it a key, and put its env variables in agent-info + +source $HOME/agent-info + + +# remote host ssh is running on a non-standard port +# security through security is a mug's game, kids, but +# it keeps my logs cleaner + +REMPORT=6666 + +# exclude what you want. I have a chroot running from which I want to exclude certain things + +/usr/bin/rsync -e "ssh -p$REMPORT" -vaSHP \ +--exclude 'chroot/home/remuser/scratch' \ +--exclude 'chroot/proc' \ +--exclude 'chroot/sys' \ +--exclude 'chroot/dev' \ +--delete \ +root@myvps.example.com:/mnt/sda/ $HOME/scratch/snapshot/myvps/snapshot/ + +# Yes, as root. I know, I'm a monster unfit for human company. + +# Also, remote host has drive I want bind mounted on /mnt/sda. +# You need to figure out how you want to deal with this yourself. + +# Wasteful, but whatever + +rm -rf $HOME/scratch/snapshot/myvps/daily/$(date +%d) + +# Also wasteful. Meh. + +cp -al $HOME/scratch/snapshot/myvps/snapshot \ + $HOME/scratch/snapshot/myvps/daily/$(date +%d) + +# Monthlies, yay. +# Script should check for and create subdirs if necessary, probably. + +if [ $(date +%d) -eq 17 ]; then + cp -al $HOME/scratch/snapshot/myvps/daily/15 \ + $HOME/scratch/snapshot/myvps/monthly/from-the-15th/$(date +%m) +fi + +# rm, cp, and date above should all be given full paths probably + +/usr/bin/logger Finished snap-and-rotate + +# Log the end. The End. +