Compare commits

17 Commits

Author SHA1 Message Date
e8025459a3 update the restic copy offsite section 2021-12-05 22:21:49 -05:00
a9dca963ad changed variable to match rest of file 2021-08-17 21:26:02 -04:00
d8333db01e updated backup command variable and changed -c argument to $2 2021-08-17 21:25:08 -04:00
c81fa4f585 removed help, made static arguments and case for them 2021-08-17 21:14:40 -04:00
cac6a07cf0 added help menu 2021-08-17 21:05:55 -04:00
50a582db92 updated sftp url 2021-08-17 20:43:41 -04:00
ff071d1d30 added logic for gauntnas local backup 2021-08-17 15:49:38 -04:00
1b5af28723 added restic repo and password default variables 2021-08-17 15:21:41 -04:00
e159085ce5 commented out the prune command 2021-08-17 15:19:06 -04:00
cccb11cd32 added restic backup and prune commands. the prune still needs work 2021-08-17 15:17:25 -04:00
4961d4b06d added quotes for comapring 2021-08-17 15:02:50 -04:00
9c7008afde updated lockfile variable 2021-08-17 14:59:05 -04:00
62b5f21b59 updated lockfile name and added restic version 2021-08-17 14:55:15 -04:00
949800c381 updated urls and added in bzip decompress command 2021-08-17 14:53:39 -04:00
3886fa064c updated restic version compare 2021-08-17 14:49:10 -04:00
fa9b0886ab updated binary path and some variables 2021-08-17 14:44:18 -04:00
42eef07387 updated top variables 2021-08-17 14:42:56 -04:00
2 changed files with 108 additions and 88 deletions

View File

@@ -1,88 +0,0 @@
#!/bin/sh
lockfile="/tmp/duplicacy.lock"
LOGFILE="/var/log/duplicacy/duplicacy_$(date +%Y%m%d-%H%M%S).log"
LATEST_DUPLICACY_VERSION="ls -lha $(dirname "$0")/binaries/ | awk '/-rw/{print substr($9,length($9)-4);exit}'"
LATEST_DUPLICACY_VERSION="2.7.2"
# make log directory
if [ ! -d $(dirname ${LOGFILE}) ]; then
mkdir $(dirname ${LOGFILE}) > /dev/null
fi
if [ -e ${lockfile} ] && kill -0 `cat ${lockfile}`; then
echo "duplicacy backup already running" >> ${LOGFILE}
exit
fi
# make sure the lockfile is removed when we exit and then claim it
trap "rm -f ${lockfile}; exit" INT TERM EXIT
echo $$ > ${lockfile}
# self update
cd $(dirname "$0")
git pull > /dev/null
# Duplicacy version update
INSTALLED_DUPLICACY_VERSION=$(duplicacy -h | awk '/VERSION:/{getline; print $1}')
if [ ${LATEST_DUPLICACY_VERSION} != ${INSTALLED_DUPLICACY_VERSION} ] || [ ! -e '/usr/bin/duplicacy' ]; then
# Determine the Kernel and Architecture
KERNEL=$(uname)
ARCH=$(uname -m)
if [ ${KERNEL} == 'Linux' ]; then
if [ ${ARCH} == 'x86_64' ]; then
curl -vL -o /usr/bin/duplicacy https://github.com/gilbertchen/duplicacy/releases/download/v${LATEST_DUPLICACY_VERSION}/duplicacy_linux_x64_${LATEST_DUPLICACY_VERSION} >> ${LOGFILE} 2>&1
chmod +x /usr/bin/duplicacy >> ${LOGFILE}
elif [ ${ARCH} == 'aarch64' ]; then
curl -vL -o /usr/bin/duplicacy https://github.com/gilbertchen/duplicacy/releases/download/v${LATEST_DUPLICACY_VERSION}/duplicacy_linux_arm64_${LATEST_DUPLICACY_VERSION} >> ${LOGFILE} 2>&1
chmod +x /usr/bin/duplicacy >> ${LOGFILE}
else
echo "Kernel Type: ${KERNEL}"
echo "Arch: ${ARCH}"
echo "Arch not supported."
exit
fi
elif [ ${KERNEL} == 'FreeBSD' ]; then
if [ ${ARCH} == 'amd64' ]; then
curl -vL -o /usr/bin/duplicacy https://github.com/gilbertchen/duplicacy/releases/download/v${LATEST_DUPLICACY_VERSION}/duplicacy_freebsd_x64_${LATEST_DUPLICACY_VERSION} >> ${LOGFILE} 2>&1
chmod +x /usr/bin/duplicacy >> ${LOGFILE}
else
echo "Kernel Type: ${KERNEL}"
echo "Arch: ${ARCH}"
echo "Arch not supported."
exit
fi
else
echo "Kernel Type: ${KERNEL}"
echo "Arch: ${ARCH}"
echo "Kernel not supported."
exit
fi
fi
# check if the /.duplicacy/preferences file exists before continuing
if [ ! -e "/.duplicacy/preferences" ] || [ ! -e "/.duplicacy/filters" ]; then
echo "ERROR: Duplicacy not yet configured. Please refer to readme file"
exit
fi
# run the backup
cd /
duplicacy -verbose -log backup -stats >> ${LOGFILE} 2>&1
# prune the backup
duplicacy -verbose -log prune -keep 0:360 -keep 30:180 -keep 7:30 -keep 1:7 >> ${LOGFILE} 2>&1
# copy the backup to offsite but only if the backup id as passed in
if [ "${1}" == "--copyOffsite" ] || [ "${1}" == "-c" ]; then
BACKUP_ID=$(awk '/"id"/{print substr($2,2,length($2)-3);exit}' /.duplicacy/preferences)
duplicacy -verbose -log copy -to GauntBackupCRO -id ${BACKUP_ID} >> ${LOGFILE} 2>&1
duplicacy -verbose -log copy -to GauntBackupGail -id ${BACKUP_ID} >> ${LOGFILE} 2>&1
duplicacy -verbose -log copy -to GauntBackupNAS -id ${BACKUP_ID} >> ${LOGFILE} 2>&1
fi
# compress the logs
gzip $(dirname ${LOGFILE})/*.log
# clean up lockfile
rm -f ${lockfile}

108
restic.sh Normal file
View File

@@ -0,0 +1,108 @@
#!/bin/sh
# restic.sh [Hostname] [-c|--copyOffsite]
# the hostname must be entered and be the first argument and is required
# the -c is optional and must be the second arguments
LOCKFILE="/tmp/restic.lock"
LOGFILE="/var/log/restic/restic_$(date +%Y%m%d-%H%M%S).log"
LATEST_RESTIC_VERSION="0.12.1"
export RESTIC_REPOSITORY="sftp://root@gauntnas.home.johnhgaunt.com:50022//mnt/restic"
export RESTIC_PASSWORD="restic"
case ${1} in
"GauntBitwarden")
BACKUP_DIRS="/etc /opt/bitwarden /var/spool/cron"
;;
"GauntNAS")
BACKUP_DIRS="/etc/version /data /root --exclude=/root/.cache"
export RESTIC_REPOSITORY="/mnt/data/backups/restic"
;;
*)
echo "Error: Hostname, ${1}, didn't match any known matches."
exit 1
;;
esac
# make log directory
if [ ! -d $(dirname ${LOGFILE}) ]; then
mkdir $(dirname ${LOGFILE}) > /dev/null
fi
if [ -e ${LOCKFILE} ] && kill -0 `cat ${LOCKFILE}`; then
echo "Restic backup already running" >> ${LOGFILE}
exit
fi
# make sure the lockfile is removed when we exit and then claim it
trap "rm -f ${LOCKFILE}; exit" INT TERM EXIT
echo $$ > ${LOCKFILE}
# self update
cd $(dirname "$0")
git pull > /dev/null
# restic version update
INSTALLED_RESTIC_VERSION=$(restic version | awk '{print $2}')
if [ "${LATEST_RESTIC_VERSION}" != "${INSTALLED_RESTIC_VERSION}" ] || [ ! -e '/usr/bin/restic' ]; then
# Determine the Kernel and Architecture
KERNEL=$(uname)
ARCH=$(uname -m)
if [ ${KERNEL} == 'Linux' ]; then
if [ ${ARCH} == 'x86_64' ]; then
curl -vL -o /usr/bin/restic.bz2 https://github.com/restic/restic/releases/download/v${LATEST_RESTIC_VERSION}/restic_${LATEST_RESTIC_VERSION}_linux_amd64.bz2 >> ${LOGFILE} 2>&1
bzip2 -fvd /usr/bin/restic.bz2 >> ${LOGFILE}
chmod +x /usr/bin/restic >> ${LOGFILE}
elif [ ${ARCH} == 'aarch64' ]; then
curl -vL -o /usr/bin/restic.bz2 https://github.com/restic/restic/releases/download/v${LATEST_RESTIC_VERSION}/restic_${LATEST_RESTIC_VERSION}_linux_arm64.bz2 >> ${LOGFILE} 2>&1
bzip2 -fvd /usr/bin/restic.bz2 >> ${LOGFILE}
chmod +x /usr/bin/restic >> ${LOGFILE}
else
echo "Kernel Type: ${KERNEL}"
echo "Arch: ${ARCH}"
echo "Arch not supported."
exit
fi
elif [ ${KERNEL} == 'FreeBSD' ]; then
if [ ${ARCH} == 'amd64' ]; then
curl -vL -o /usr/bin/restic.bz2 https://github.com/restic/restic/releases/download/v${LATEST_RESTIC_VERSION}/restic_${LATEST_RESTIC_VERSION}_freebsd_amd64.bz2 >> ${LOGFILE} 2>&1
bzip2 -fvd /usr/bin/restic.bz2 >> ${LOGFILE}
chmod +x /usr/bin/restic >> ${LOGFILE}
else
echo "Kernel Type: ${KERNEL}"
echo "Arch: ${ARCH}"
echo "Arch not supported."
exit
fi
else
echo "Kernel Type: ${KERNEL}"
echo "Arch: ${ARCH}"
echo "Kernel not supported."
exit
fi
fi
# run the backup
restic --cleanup-cache --verbose backup ${BACKUP_DIRS} >> ${LOGFILE} 2>&1
# prune the backup
#restic --verbose forget --keep-daily 7 --keep-weekly 5 --keep-monthly 12 --keep-yearly 75 --prune >> ${LOGFILE} 2>&1
# copy the backup to offsite if requested
if [ "${2}" == "--copyOffsite" ] || [ "${2}" == "-c" ]; then
#$ restic -r /srv/restic-repo copy --repo2 /srv/restic-repo-copy --host luigi
restic --verbose copy --repo2 sftp://root@gauntbackupCRO.home.johnhgaunt.com://backup/restic --host ${1} --copy-chunker-params >> ${LOGFILE} 2>&1
restic --verbose copy --repo2 sftp://root@gauntbackupGail.home.johnhgaunt.com://backup/restic --host ${1} --copy-chunker-params >> ${LOGFILE} 2>&1
restic --verbose copy --repo2 sftp://root@gauntbackupNAS.home.johnhgaunt.com://backup/restic --host ${1} --copy-chunker-params >> ${LOGFILE} 2>&1
restic --verbose copy --repo2 sftp://root@GauntBackupGCE01.home.johnhgaunt.com://backup/restic --host ${1} --copy-chunker-params >> ${LOGFILE} 2>&1
fi
# compress the logs
gzip $(dirname ${LOGFILE})/*.log
# clean up lockfile
rm -f ${LOCKFILE}