t-t-t-t-t
11/21/2019 - 11:34 PM

[back up scripts - set 1] #backup

[back up scripts - set 1] #backup

# File: /usr/local/etc/backup-blacklist.conf
/lost+found
/backup/*
/dev/*
/proc/*
/sys/*
/tmp/*
/run/*
/mnt/*
/media/*
/var/log/*
/var/cache/pacman/pkg/*
/var/lib/aurbuild/*
/var/lib/docker/*
/root/.cache/*
/home/*/.cache/*
/home/*/.local/share/Trash/*
/home/*/.thumbnails/*
#!/bin/sh
# File: /usr/local/bin/backup-compress.sh
NUM_FILES_TO_KEEP=2
HOST=`hostname -s`
FILENAME=/backup/archive_$HOST\_`date +%Y.%m.%d`.tar.gz 

if [[ $EUID -ne 0 ]]; then
  echo "Must be run as root"; exit 1
fi

cd /backup

# Delete old backups
rm -f `ls -t archive_*.tar.gz | awk "NR>$NUM_FILES_TO_KEEP"`

logger -s "Starting backup compression"
tar czf $FILENAME $HOST
logger -s "Finished backup compression"

/usr/local/bin/backup-export.sh $FILENAME
#!/bin/sh
# File: /usr/local/bin/backup-export.sh
EXTERNAL_DRIVE=/run/media/z/Elements-1
ARCHIVE_FILE="$1"

if [ -z "$1" ]; then
  echo "Please specify the full path of the archive file."
fi

if mount | grep $EXTERNAL_DRIVE > /dev/null; then
  logger -s "Exporting backup to external drive..."
  cp $ARCHIVE_FILE $EXTERNAL_DRIVE
  logger -s "Backup export complete."
else
  logger -s "External drive not mounted. Exiting..."
fi
#!/bin/sh
# File: /usr/local/bin/backup-sync.sh
SRC=/
DST=/backup/`hostname -s`
BLACKLIST=/usr/local/etc/backup-blacklist.conf

# Sanity check
if [[ $EUID -ne 0 ]]; then
  echo "This script must be run as root"; exit 1
fi

logger -s "Starting filesystem sync"
rsync -aAXS --delete-excluded --exclude-from=$BLACKLIST $SRC $DST
logger -s "Finished filesystem sync"

$ sudo fcrontab -e

#Add the following lines to root’s crontab:

@hourly flock -n /tmp/backup.lock /usr/local/bin/backup.sh @daily flock /tmp/backup.lock /usr/local/bin/compress-backup.sh

#The use of flock and the lock file ensures that the script will not run if another backup job is currently running. The only #thing that needs to be done manually is cleanup of old files from the external drive, which is rarely necessary if your #external is sufficiently large.

#If you find that running the compression job every day is taxing your system, you could run it every three days with the #following cron entry:

0 0 */3 * * flock /tmp/backup.lock /usr/local/bin/backup-compress.sh