Skip to content
Browse files

Added scheduled backup script for MySQL and PostgreSQL

  • Loading branch information...
1 parent ddf181a commit 28d75b1a50678bfe24d12cedaef845acae9d10d4 @mikeplate committed May 16, 2012
Showing with 22 additions and 5 deletions.
  1. +8 −0 mysql-setup.sh
  2. +14 −5 postgresql-setup.sh
View
8 mysql-setup.sh
@@ -33,6 +33,14 @@ EOF
chown root:root /root/.my.cnf
chmod 600 /root/.my.cnf
+# Set up backup
+cp mysql-backup.sh /usr/local/sbin/mysql-backup.sh
+chmod u+x /usr/local/sbin/mysql-backup.sh
+crontab -l | grep -q mysql-backup.sh
+if [ $? -ne 0 ]; then
+ crontab -l | (cat; echo '25 23 * * * /usr/local/sbin/mysql-backup.sh') | crontab -
+fi
+
# Get version for display purposes
MYSQLVER=$(mysqld --version)
[[ $MYSQLVER =~ Ver\ ([0-9.]+) ]]
View
19 postgresql-setup.sh
@@ -21,11 +21,6 @@ if [ $? -ne 0 ]; then
exit $?
fi
-# Get version for display purposes
-PSQLVER=$(psql --version)
-[[ $PSQLVER =~ [0-9.]+ ]]
-PSQLVER=$BASH_REMATCH
-
# Install libraries
echo 'Installing PostgreSQL libraries'
gem install dm-postgres-adapter -q >> tmp/logfile
@@ -39,5 +34,19 @@ if [ $? -ne 0 ]; then
exit $?
fi
+# Set up backup
+echo 'Schedule backup'
+cp postgresql-backup.sh /usr/local/sbin/postgresql-backup.sh
+chmod u+x /usr/local/sbin/postgresql-backup.sh
+crontab -l | grep -q postgresql-backup.sh
+if [ $? -ne 0 ]; then
+ crontab -l | (cat; echo '45 23 * * * /usr/local/sbin/postgresql-backup.sh') | crontab -
+fi
+
+# Get version for display purposes
+PSQLVER=$(psql --version)
+[[ $PSQLVER =~ [0-9.]+ ]]
+PSQLVER=$BASH_REMATCH
+
echo "PostgreSQL version $PSQLVER installed successfully"

0 comments on commit 28d75b1

Please sign in to comment.
Something went wrong with that request. Please try again.