Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

If you store the files inside an LVM volume, you could lock the database and then both do an mysqldump and make an LVM snapshot, and finally unlock the database. Then backup from the LVM snapshot. In that way, you'd have synchronized DB and FS contents with minimal locking time.

share|improve this answer
    
Yeah, LVM would be awesome. I was wondering if this problem could be solved from the "shell level". –  Oliver Salzburg Feb 22 '12 at 12:27
1  
No, you'll need some sort of transaction to make a point-in-time snapshot of the filesystem. Whether that comes from LVM, btrfs, ZFS, VSS (on Windows), or something completely different -- it often relies on OS or filesystem-level support. There's no hacky shell tricks you can pull that involve keeping the site online otherwise, unless you rearchitect the entire site to allow for backup windows where all writes go to a staging area until the backup completes, then the site migrates all those temporary writes back into the main storage. –  afrazier Feb 22 '12 at 14:08
    
To add to your answer. There are existing methods to achieve what I want. These methods exist in the form of LVM. There is no simpler approach and if you want to do it properly, do it properly and don't try to hack it :P –  Oliver Salzburg May 3 '12 at 12:22

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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