diff --git a/gauntmta_backup.sh b/gauntmta_backup.sh index c1c2b0d..689bb3d 100644 --- a/gauntmta_backup.sh +++ b/gauntmta_backup.sh @@ -1,23 +1,32 @@ - #!/bin/bash - #We can work out if the day of the week with date +%a Mon Tue Wed Thu Fri Sat Sun +#!/bin/bash +# Variables DATE=$(date +%Y%m%d-%H%M%S) BACKUP_DIR=/backups -SNAR=${BACKUP_DIR}/GauntMTA.snar -TAR=${BACKUP_DIR}/GauntMTA Backup ${DATE}.tgz +DIRS_TO_BACKUP="/etc /opt /root /home /var" +TAR="${BACKUP_DIR}/GauntMTA Backup ${DATE}.tgz" -#If it is Monday we need to make sure that we start with a new snar file to ensure full #backup -#If the snar file is there it is renamed with a date extension of the previous Monday -if [ $(date +%a) = 'Mon' ]; then - test -e ${SNAR} ${SNAR}.$(date --date '7 days ago' +%F) -fi -#tar -cvpzSg "${SNAR}" -f "${TAR}" --exclude="${BACKUP_DIR}" --exclude=/proc --exclude=/tmp --exclude=/mnt --exclude=/dev --exclude=/sys --exclude=/run --exclude=/media --exclude=/var/cache/apt/archives --one-file-system / +# pre backup commands +crontab -l > /root/crontab.txt -tar -cvpSzg "${SNAR}" -f "${TAR}" --exclude="${BACKUP_DIR}" --one-file-system / +# create the backup +tar -cpSzf "${TAR}" --exclude="${BACKUP_DIR}" --exclude=/var/cache --exclude=/var/mail ${DIRS_TO_BACKUP} +# sync the backup directory to seafile +rclone sync /backups/ seafile: + +# only keep 14 copies on local disk, seafile will keep deleted history +# https://stackoverflow.com/questions/25785/delete-all-but-the-most-recent-x-files-in-bash +ls -tp | grep -v '/$' | tail -n +15 | xargs -I {} rm -- {} + + +:' # this is so ugly, need a better solution for what programs are installed/used and their configurations. # Programs that are installed: # postfix # spamassians +# opendkim +# opendkim-tools +# openvpn # certbot (letsencrypt) @@ -549,4 +558,5 @@ xinetd install xz-utils install zabbix-agent install zabbix-release install -zlib1g:amd64 install \ No newline at end of file +zlib1g:amd64 install +' \ No newline at end of file