Changes to backup scripts

master
Nathan Steel 9 months ago
parent 35fe368dad
commit c9c67dd9e9

@ -1,12 +1,11 @@
#!/bin/bash
# Cronjob needs to be on one line, spaced out for example/ in-case running cronjob from a script that just runs the below
# e.g. 0 0 * * * /home/nathan/backupScripts/docker_backup.sh \
# -c "duckdns homer" \
# -d /home/samba/share/Docker_prod \
# e.g. 0 0 * * * /home/nathan/scripts/backup/borg/directory_backup.sh \
# -d "/home/nathan/AA/A /home/nathan/AA/C" \
# -b /home/nathan/testBack \
# -r pi2 \
# -R ~/backups/pi1/docker
# -R ~/backups/pi1/AA
while getopts d:b:r:R: flag
do
@ -18,24 +17,65 @@ do
esac
done
# As this is using borg, DIR can be passed as "~/dir2 ~/dir2" rather than a single directory
# /var/spool/cron/crontabs # Cron backup
# Function(s)
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 24 hours of backups, 7 daily backups (one a day/week), 4 weekly (one a week for a month)
borg prune \
--glob-archives '{hostname}-*' \
--keep-hourly 24 \
--keep-daily 7 \
--keep-weekly 4
}
offsite_borg () {
export BORG_REPO=$REMOTE:$REMOTE_DIR
borg create ::{hostname}-{now} $DIR # Backup with of the directory itself (seperate borg repo)
}
offsite_prune () {
# Prune on server, this may take ages though so I'm not sure about this...
# 3 hourly, is hopefully 8 hour intervals of the day
borg prune \
--glob-archives '{hostname}-*' \
--keep-hourly 3 \
--keep-daily 7 \
--keep-weekly 4
}
# Script
# LOCAL
export BORG_REPO=$BACKUP_DIR
borg create ::{hostname}-{now} $DIR
#rdiff-backup $DIR/$i $BACKUP_DIR/$i # If a directory doesn't exist, it get created too
borg_backup
borg_prune # Run prune bash script
# Keep last 24 hours of backups, 7 daily backups (one a day/week), 4 weekly (one a week for a month), and 6 monthly, and 1 a year
borg prune \
--glob-archives '{hostname}-*' \
--keep-hourly 24 \
--keep-daily 7 \
--keep-weekly 4
# Offsite
if (ssh $REMOTE ls $REMOTE_DIR 2>/dev/null);
then
offsite_borg
else
# Doesn't exist, create, and init repo first
ssh $REMOTE mkdir -p $REMOTE_DIR
borg init --encryption=none $REMOTE:$REMOTE_DIR
offsite_borg
fi
# Create the remote directory for backup if it doesn't exist
ssh $REMOTE mkdir -p $REMOTE_DIR
offsite_prune # Seperate, for docker script i.e. backup each container in loop, and prune after ALL containers looped and back up
# so to not keep the containers down for excessively long amounts of time
rsync -azh -e ssh \
--delete \
$BACKUP_DIR \
$REMOTE:$REMOTE_DIR
# OLD backup, where I rsynced an entire rdiff directory from local to offsite
# Create the remote directory for backup if it doesn't exist
# ssh $REMOTE mkdir -p $REMOTE_DIR
# rsync -azh -e ssh \
# --delete \
# $BACKUP_DIR \
# $REMOTE:$REMOTE_DIR

@ -1,7 +1,7 @@
#!/bin/bash
# Cronjob needs to be on one line, spaced out for example/ in-case running cronjob from a script that just runs the below
# e.g. 0 0 * * * /home/nathan/backupScripts/docker_backup.sh \
# e.g. 0 0 * * * /home/nathan/scripts/backup/borg/docker_backup.sh \
# -c "duckdns homer" \
# -d /home/samba/share/Docker_prod \
# -b /home/nathan/testBack \

@ -1,9 +1,23 @@
#!/bin/bash
source /home/nathan/backupScripts/docker_backup.sh \
-c "duckdns homer" \
-d /home/samba/share/Docker_prod \
-b /home/nathan/testBack \
# DOCKER BACKUP
# source /home/nathan/scripts/backup/borg/docker_backup.sh \
# -c "duckdns homer" \
# -d /home/samba/share/Docker_prod \
# -b /home/nathan/testBack \
# -r pi2 \
# -R ~/backups/pi1/docker \
# -N 0
# DIRECTORY BACKUP
source /home/nathan/scripts/backup/borg/directory_backup.sh \
-d "/home/nathan/AA/A /home/nathan/AA/C" \
-b /home/nathan/testBack/dir \
-r pi2 \
-R ~/backups/pi1/AA
source /home/nathan/scripts/backup/borg/directory_backup.sh \
-d /var/spool/cron/crontabs \
-b /home/nathan/testBack/cron \
-r pi2 \
-R ~/backups/pi1/docker \
-N 0
-R ~/backups/pi1/cron

@ -0,0 +1,3 @@
# Mount the drive letter, to a location
sudo mount -t drvfs K: /mnt/k
# Using K as it's super irregular, so suitable for backup in-case other drives are mounted
Loading…
Cancel
Save