So, i ‘ve been having some problems. I wanted to feel free to experiment with drupal in my Fedora Core 17 machine, but how could i do this, if i wouldn’t be able to restore fast and easy to a previous working conditions, if everything went wrong. Backup and Migrate module, only seems to offer database backup and various permission problems would come up if i tried to backup from within drupal. Moreover SELinux would complain, if i tried to backup to a folder out of apache’s evil domain. The SELinux problem can be handled, by only changing one boolean value:
setsebool -P httpd_read_user_content 1
but this, will leave me with a testing enviroment, altered from a production one. On the other hand, drush, which offers a command-line and a full backup, meaning it includes both the server files and the database, comes with certain bugs and needs various modifications in order to restore a backup. Bugs and tweaks, which i wasn’t ready or willing to learn and adapt to. Git also proves a little “too-much-of-a-machine” for a simple drupal backup and it also cant backup the database. So… i ‘ve spent some time, writing my own script. :)
What it does essentially, is backing up the whole apache root directory, and extracting the drupal databases by reading the “settings.php” file of every installed site, if there is more than one. Then, when restoring, it deletes all apache content, deploy the tarballed file backup and restore the saved databases. Trying to be more specific, what i tried to do was:
find /var/www/html/ -name 'settings.php'
find one or more settings.php files in apache, where drupal keeps, among others, the assigned mysql database for every site, extract the database name, with some perl regexes,
mysqldump -u root -p[password] --databases [database1 database2 ...] > databasedump.sql
access the found databases as root and dump them to a file with mysqldump at the apache root directory,
tar -cjpf tarball.tar.bz2 -C /var/www/html/ ./
and finally compress the everything that’s in the apache root directory, with the dumped mysql. When i need to restore something, i simply wipe the apache root direcotry, untar my tarball, and restore the dumped mysql with
mysql -u root -p[password] < databasedump.sql
I used tar, so i can keep file permissions, with this “-p” flag, and bzip2 compression, since the backups won’t be incrmental and due to the backups size, I didn’t consider it as problem. I just tried to create something simple and effective to keep working on my drupal testing site. It seems pretty handy to me for an offline server, used just for beta testing. I also added the ability to comment every backup, so you ‘d know what you are restoring. This is my code. A bit brute but in my opinion, outruns the complexity and necessitiy of something more diverse and elegant, if you just need something for backup in the testing procedure.