I have a small server and want to create a safety backup to my home.
How do I best achieve this?
I read about rsync, however, as far as I understand it may make files in use be inconsistent.
E.g. my mysql data-file may be inconsistent, resulting in the database being useless. This is bad.
How to best make a backup with everything being consistent?
Any tips on what to use and especially whether restoring the backup works fine?
1 Answer
You need to use 2-step-backup:
- Make a MySQL Dump on a remote host.
# mkdir /backups
# mysqldump -A > /backups/all-databases.sql
- Make a File Dump on remote host.
# tar -cvpf /backups/fullbackup.tar --directory=/ --exclude=proc --exclude=sys --exclude=dev/pts --exclude=backups .
(You can also exclude /var/lib/mysql, but i dont do this)
You can do all that by the cron and get 2 files all-databases.sql and fullbackup.tar by rsync. It can not make an inconsistent data.
-
Does this mean, that there is no solution to the inherent problem? That I have to make a seperate backup-"hack" for all programs that potentially modify a file? Aug 26, 2014 at 8:51
-
Yes, you need to take care of program, that can modify its variable data during making the backup. Often you need do this only with Databases. Aug 26, 2014 at 10:12
-
"It can not make an inconsistent data" – this statement is wrong. You can still get inconsistent data as tar doesn't create a filesystem snapshot. The MySQL dump will be consisntent but other files might have changed in the mean time. If you need consistent data you should have a look at lvm snapshots and similar techniques which increase the likelihood of getting consistent data. Jun 10, 2015 at 21:01