Editing
Backup mySQL-database with a cronjob
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
The script described below and the backups should be saved somewhere on volume1. You have to edit the script to match your preferred path. You also have to enter your sql-password in the script. 1. Put the code below into a file called mysqlbackup.sh: <pre>#!/bin/bash # number of backups to be saved KEEP=2 BACKUPS=`find /volume1/path/sqlbackup -name "mysqldump-*.gz" | wc -l | sed 's/\ //g'` while [ $BACKUPS -ge $KEEP ] do ls -tr1 /volume1/path/sqlbackup/mysqldump-*.gz | head -n 1 | xargs rm -f BACKUPS=`expr $BACKUPS - 1` done DATE=`date +%Y%m%d%H%M%S` rm -f /volume1/path/sqlbackup/.mysqldump-${DATE}.gz_INPROGRESS /usr/syno/mysql/bin/mysqldump --opt -uroot -psqlpassword --all-databases | gzip -c -9 > /volume1/path/sqlbackup/.mysqldump-${DATE}.gz_INPROGRESS mv -f /volume1/path/sqlbackup/.mysqldump-${DATE}.gz_INPROGRESS /volume1/path/sqlbackup/mysqldump-${DATE}.gz exit 0</pre> 2. This file has to be saved to /volume1/'''path'''. 3. Make a subdirectory /volume1/'''path'''/sqlbackup 4. For a test you can run the script with "sh /volume1/'''path'''/mysqlbackup.sh". When you start the script, the old backups will be deleted and after that the backup will start. 5. Finally you have to add this script to /etc/crontab to have the script run at a specific time. Add the following line into the crontab: <pre>1 0 * * * root sh /volume1/path/mysqlbackup.sh</pre> The script will start every day at 0:01h (just after the time update). 6. Restart your Synology Station to activate the new crontab or alternatively send a SIGHUP signal to the crond process to force a rescan of the crontab: <pre> > ps | grep crond | grep -v grep 1229 root 580 S /usr/sbin/crond > kill -HUP 1229</pre> [[Category:SynologyWiki]] [[Category:ToBeExported]]
Summary:
Please note that all contributions to wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Wiki:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Log in
Namespaces
Page
Discussion
British English
Views
Read
Edit
View history
More
Search
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Tools
What links here
Related changes
Special pages
Page information