commit 3e62fd7f1c3114143a6f0e9e50b5a1b9b4c79247
parent d7136ee6a1040e82ff3af42cc21be0144605ef00
Author: John Kubach <johnkubach@gmail.com>
Date: Sun, 31 Mar 2019 22:09:06 -0400
Update Script
- Add mysqldump call
- Update backup path arguments
- Update find call
Diffstat:
1 file changed, 9 insertions(+), 10 deletions(-)
diff --git a/databaseBackup.sh b/databaseBackup.sh
@@ -1,12 +1,12 @@
#!/bin/bash
# DATABASE BACKUP SCRIPT
# POPULATE THE FOLLOWING VARIABLES:
-# DATABASELOCATION, BACKUPLOCATION
+# WORKINGDIR, BACKUPLOCATION
DATE=$(date +%F.%T)
-# Location of database file(s)
-DATABASELOCATION=""
+WORKINGDIR="/home/ec2-user/db_backups"
+cd $WORKINGDIR
# Three different arguments may be specified.
# -d : daily backup
@@ -16,15 +16,14 @@ while getopts dwm option
do
case "${option}"
in
- d) BACKUPLOCATION="/daily";;
- w) BACKUPLOCATION="/weekly";;
- m) BACKUPLOCATION="/monthly";;
+ d) BACKUPLOCATION="daily";;
+ w) BACKUPLOCATION="weekly";;
+ m) BACKUPLOCATION="monthly";;
esac
done
-rsync -rav $DATABASELOCATION $BACKUPLOCATION/$DATE
+# rsync -rav $DATABASELOCATION $BACKUPLOCATION/$DATE
+mysqldump --all-databases > $BACKUPLOCATION/$DATE.sql
# Only keep 2 backups
-find $BACKUPLOCATION/* -type d | sort -r | sed -n '3,$p' | xargs rm -r
-
-# TODO: Check if there are more that 2 backups before attempting to remove
+find $BACKUPLOCATION/* -type f | sort -r | sed -n '3,$p' | xargs rm