From d0680fd10cde9437c062f52bf906b5c80e9c7466 Mon Sep 17 00:00:00 2001 From: Jonathan Hodgson Date: Mon, 8 Jan 2018 16:51:10 +0000 Subject: [PATCH] Add simple rsync script for backing up to server --- bin/backup | 27 +++++++++++++++++++++++++++ bin/backupExcludes | 2 ++ 2 files changed, 29 insertions(+) create mode 100755 bin/backup create mode 100644 bin/backupExcludes diff --git a/bin/backup b/bin/backup new file mode 100755 index 00000000..f4db5708 --- /dev/null +++ b/bin/backup @@ -0,0 +1,27 @@ +#!/usr/bin/bash + +#Directory on the server to backup to +BACKUPDIR='/mnt/TimeMachine/Backup-JH/backups/' +LATEST=$(ssh officeServerJH find ${BACKUPDIR} -type d -depth 1 | sort | tail -n 1) +TODAY=$(date -I -d "today") +echo ${LATEST##*\/} +echo ${TODAY} + +#This can be tricked by having a folder with a date after the current date +if [[ ${LATEST##*\/} = ${TODAY} ]]; then + echo "There already seems to have been a backup today" + echo "If you want to rename the folder ${LATEST} then run again" + exit 0 +fi + +#Backup sites directory +rsync --archive --one-file-system --hard-links --human-readable --inplace\ + --exclude-from=./backupExcludes\ + --link-dest=${LATEST}\ + ~/Sites officeServerJH:/mnt/TimeMachine/Backup-JH/backups/${TODAY}/ --verbose + +#Backup Documents Directory +rsync --archive --one-file-system --hard-links --human-readable --inplace\ + --exclude-from=./backupExcludes\ + --link-dest=${LATEST}\ + ~/Documents officeServerJH:/mnt/TimeMachine/Backup-JH/backups/${TODAY}/ --verbose diff --git a/bin/backupExcludes b/bin/backupExcludes new file mode 100644 index 00000000..c8dbc491 --- /dev/null +++ b/bin/backupExcludes @@ -0,0 +1,2 @@ +.git/ +node_modules/