Add USB backup for fedora install

master
Nathan Steel 5 months ago
parent 64c9ec7ab6
commit 5b49f1ab5f

@ -0,0 +1,59 @@
#!/bin/sh
# 0 * * * * /home/nathan/Documents/backup.sh
# Check if the USB is plugged in (Gnome auto-mounts to /run/media)
USB="/run/media/$USER/sd_backup";
if [[ ! -d $USB ]]; then
exit 1 # sd_backup is not plugged in;
fi
USB_DIR="/fedora/borg";
DIRS="git nas 360ss";
BASE_DIR="/home/nathan/Documents/";
# Basically the code from directory_backup in scripts.git
borg_backup (){
if [ ! -d "$BACKUP_DIR" ]; then
mkdir -p $BACKUP_DIR
borg init --encryption=none $BACKUP_DIR
fi
export BORG_REPO=$BACKUP_DIR
borg create ::{hostname}-{now} $DIR
}
borg_prune () {
# Keep last 12 hours, 7 days, 4 weeks worth of backups
# LESS for local to save storage
borg prune \
--glob-archives '{hostname}-*' \
--keep-hourly 12 \
--keep-daily 7 \
--keep-weekly 4
# Then clear up the disk space of the files removed via prune
borg compact
}
# Also do an rsync, so there's an accessible clone of data on USB
# makes it easier to drop things between PCs, but it is a CLONE
rsync_backup (){
if [ ! -d "$CLONE_DIR" ]; then
mkdir -p $CLONE_DIR;
fi
# avh with --dry-run when testing
# Contents of directory for rsync (extra /)
rsync -avh $DIR/ $CLONE_DIR \
--delete-before
}
for bDir in $DIRS
do
BACKUP_DIR=$USB$USB_DIR/$bDir;
CLONE_DIR=$USB/fedora/rsync/$bDir;
DIR=$BASE_DIR$bDir;
borg_backup
borg_prune
rsync_backup
done
Loading…
Cancel
Save