From 30644913457519c0875ecf70590e1f2c511ad5ad Mon Sep 17 00:00:00 2001 From: Jonathan Hodgson Date: Sat, 7 Jul 2018 13:42:47 +0100 Subject: [PATCH] Updates backup script, adds database backup script and modifies extract script --- bin/backup | 6 +++--- bin/backupDatabases | 15 +++++++++++++++ bin/extract | 8 ++++++++ 3 files changed, 26 insertions(+), 3 deletions(-) create mode 100755 bin/backupDatabases diff --git a/bin/backup b/bin/backup index a6b6caf5..77557a89 100755 --- a/bin/backup +++ b/bin/backup @@ -2,7 +2,7 @@ #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) +LATEST=$(ssh officeServerJH ls ${BACKUPDIR} | sort | tail -n 1) TODAY=$(date -I -d "today") echo ${LATEST##*\/} echo ${TODAY} @@ -17,13 +17,13 @@ fi #Backup sites directory rsync --archive --one-file-system --hard-links --human-readable --inplace\ --exclude-from=./backupExcludes\ - --link-dest=${LATEST}\ + --link-dest=${BACKUPDIR}${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}\ + --link-dest=${BACKUPDIR}${LATEST}\ ~/Documents officeServerJH:/mnt/TimeMachine/Backup-JH/backups/${TODAY}/ --verbose #At some point, add ability to delete old backups diff --git a/bin/backupDatabases b/bin/backupDatabases new file mode 100755 index 00000000..aaa41729 --- /dev/null +++ b/bin/backupDatabases @@ -0,0 +1,15 @@ +#! /bin/bash +TIMESTAMP=$(date +"%F") +BACKUP_DIR="$HOME/Sites/db-backups" +MYSQL_USER="root" +MYSQL_PASSWORD="root" +MYSQL=/opt/lampp/bin/mysql +MYSQLDUMP=/opt/lampp/bin/mysqldump + +mkdir -p "$BACKUP_DIR" + +databases=`$MYSQL --user=$MYSQL_USER -p$MYSQL_PASSWORD -e "SHOW DATABASES;" | grep -Ev "(Database|information_schema|performance_schema)"` + +for db in $databases; do + $MYSQLDUMP --force --opt --user=$MYSQL_USER -p$MYSQL_PASSWORD --databases $db | gzip > "$BACKUP_DIR/$db-$TIMESTAMP.sql.gz" +done diff --git a/bin/extract b/bin/extract index 768b5ded..7a903033 100755 --- a/bin/extract +++ b/bin/extract @@ -31,6 +31,14 @@ if [ -f $1 ] ; then gunzip $1 fi ;; + *.rar) + if [ "$2" ]; then + #tar xvf $1 -C $2 + echo "Look into how to unrar into directory" + else + unrar x $1 + fi + ;; *.tar) if [ "$2" ]; then tar xvf $1 -C $2