I have a web-application that stores data into a MySQL database and on the filesystem. Some of the database records reference some of the files on the filesystem.
Now I want to create a snapshot of the whole lot. Of course, I want to make sure that aftwards, all files referenced in the database snapshot are present in the filesystem snapshot. And all files in the filesystem snapshot are properly referenced in the database snapshot.
If I would run
mysqldump first and then
tar up the files (or the other way around), there is a certain race condition. On top of that, I doubt anything is stopping other processes from changing files while I run my backup.
My first thought was to simply
chmod 444 the directory before starting the backup process. But I'm not sure about all the negative implications that would bring to a live system (I can imagine a few).
Obviously, in this case, I could simply shut down Apache and, thus, prevent any changes while I do my backup. But shutting off the web server isn't the most elegant solution either.