So my intention is to backup some key directory with my documents and my MySQL data file etc. I have a cronjob set and it seems to work for all commands in there. Files are copied daily into a backup drive.

It's just that the one that is supposed to copy the MySQL folder contents, is just copying the folder but no contents.

I left the forward slash "/" off at the end of all the directories because I read this means to copy all the info in the directory.

Any ideas why the command create and copies the MYSQL directory to my backup location but no files. Is it a permissions thing that only the root user can do this? if so how do I get this done?

My crontab file contains:

44 4 * * * /usr/bin/rsync -av --delete /var/www/html /media/stan/Seagate\ Expansion\ Drive/backups/
33 3 * * * /usr/bin/rsync -av --delete /home/stan/documents /media/stan/Seagate\ Expansion\ Drive/backups/
03 3 * * * /usr/bin/rsync -av /var/lib/mysql /media/stan/Seagate\ Expansion\ Drive/backups/
02 2 * * * /usr/bin/rsync -av --delete /var/backups /media/stan/Seagate\ Expansion\ Drive/backups/

UPDATE: I ran the particular command from the commandline and got the below errors:

stan@corsair:~$ /usr/bin/rsync -av /var/lib/mysql /media/stan/Seagate\ Expansion\ Drive/backups/
sending incremental file list
rsync: opendir "/var/lib/mysql" failed: Permission denied (13)

sent 73 bytes  received 20 bytes  186.00 bytes/sec
total size is 0  speedup is 0.00
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1183) [sender=3.1.0]

EDIT. Solution I used I decided that rsync is not the best tool for this since I have to stop the MySQL server. I went with @AB's mysqldump suggestion.

The final command added much needed compression which saves like 75% space on each backup:

mysqldump -u root -pmypass --all-databases | gzip >  /media/stan/Seagate\ Expansion\ Drive/backups/mysql/mysqlbak-$(date  "+\%Y-\%m-\%d_\%H:\%M:\%S").sql.gz
  • What happens when you run the non-working command manually? – Sledge Hammer Jun 12 '15 at 14:33
  • Stop the mysql server before you start rsync. – A.B. Jun 12 '15 at 14:34
  • You might want to stop the MySQL server first as @A.B. suggested and if that still doesn't help you can try running the command with sudo in front of it. //EDIT: Note that backing up the MySQL files while the server is running is not a good idea and you might want to think of a different solution like mysqlhotcopy if the tables are MyISAM or something like percona's xtrabackup for InndoDB – Sledge Hammer Jun 12 '15 at 14:38

Stop the MySQL server before you start the backup

sudo service mysql stop

And you have a permission problem

rsync: opendir "/var/lib/mysql" failed: Permission denied (13)

therefore use the crontab of your root:

sudo crontab -e

I would prefer a backup with mysqldump. Thus, the service must be neither stopped nor restarted.

mysqldump -u root -p --all-databases > /media/stan/Seagate\ Expansion\ Drive/backups/

Or taken from the comments (@NormanBird) below, with gzip

mysqldump -u root -pmypass --all-databases | gzip > /media/stan/Seagate\ Expansion\ Drive/backups/mysql/mysqlbak-$(date "+\%Y-\%m-\%d_\%H:\%M:\%S").sql.gz
  • I tested and will go with the mysqldump option, which I have used before but I completely forgot and was in rsync mode :-). I used a command that also compresses the file by about 75%, which is always cool. Thanks for this reminder and I will select your answer @AB out of appreciation. – Norman Bird Jun 12 '15 at 15:51
  • here is the mysqldump I went with: mysqldump -u root -pmypass --all-databases | gzip > /media/stan/Seagate\ Expansion\ Drive/backups/mysql/mysqlbak-$(date "+\%Y-\%m-\%d_\%H:\%M:\%S").sql.gz – Norman Bird Jun 12 '15 at 15:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.