Bug 8268: Add database dump to export tool
[koha.git] / misc / cronjobs / backup.sh
index 38026cb..0806c6c 100755 (executable)
@@ -1,23 +1,19 @@
 #!/bin/sh
 # Script to create daily backups of the Koha database.
 # Based on a script by John Pennington
+BACKUPDIR=`xmlstarlet sel -t -v 'yazgfs/config/backupdir' $KOHA_CONF`
 KOHA_DATE=`date '+%y%m%d'`
-KOHA_DUMP=/tmp/koha-$KOHA_DATE.dump
-KOHA_BACKUP=/tmp/koha-$KOHA_DATE.dump.gz
+KOHA_BACKUP=$BACKUPDIR/koha-$KOHA_DATE.sql.gz
 
-mysqldump --single-transaction -u koha -ppassword koha > $KOHA_DUMP &&
-gzip -f $KOHA_DUMP &&
-# Creates the dump file and compresses it;
-# -u is the Koha user, -p is the password for that user.
-# The -f switch on gzip forces it to overwrite the file if one exists.
+mysqldump --single-transaction -u koha -ppassword koha | gzip -9 > $KOHA_BACKUP
 
-mv $KOHA_BACKUP /home/kohaadmin &&
-chown kohaadmin.users /home/kohaadmin/koha-$KOHA_DATE.dump.gz &&
-chmod 600 /home/kohaadmin/koha-$KOHA_DATE.dump.gz &&
+#mv $KOHA_BACKUP /home/kohaadmin &&
+#chown kohaadmin.users /home/kohaadmin/koha-$KOHA_DATE.dump.gz &&
+#chmod 600 /home/kohaadmin/koha-$KOHA_DATE.dump.gz &&
 # Makes the compressed dump file property of the kohaadmin user.
 # Make sure that you replace kohaadmin with a real user.
 
-echo "$KOHA_BACKUP was successfully created." | mail kohaadmin -s $KOHA_BACKUP ||
+[ -f $KOHA_BACKUP] && echo "$KOHA_BACKUP was successfully created." | mail kohaadmin -s $KOHA_BACKUP ||
 echo "$KOHA_BACKUP was NOT successfully created." | mail kohaadmin -s $KOHA_BACKUP
 # Notifies kohaadmin of (un)successful backup creation
 # EOF