Tuesday, March 21, 2006

Backing up User Accounts on Ensim Including MySQL databases

So I have been working on migrating servers. Unfortunately one of my old servers uses Ensim (I prefer plain servers with no control panel).

I had to backup all the user accounts but not the extraneous stuff that Ensim generates for each user account. On some of my servers I had more than 100 domains hosted. Ensim does offer a solution to backup accounts but it specializes in creating corrupted backup for me or in case it does backs up, it does so with a lot of stuff that I don't need.

For instance I am not interested in backing up the user stats. However I do want to backup user created databases, stored in /var/lib/mysql directory under User's virtual file system.

I came across a variety of custom backup solutions ranging from $30 to $100.

With five minutes of thinking, I wrote my own.

Here, you can have it for free (not that I don't like donations which can be sent via Paypal to adoppt at adoppt dot com.

It is very extendable as you can see. However, please don't use it if you don't understand what it's doing. Caution: there's a remove command which removes the archives file after transporting it to the new server.

A report is generated in report.txt file. Before beginning, create a /backups directory and navigate to /home/virtual directory. Then run it and relax :)

Make sure you have set up a passwordless entry before continuing or else be prepared to be a parrot repeating password after each transfer.

Directories that are backed up for each site:


Archive, Compress, Verify, Transfer Securely, Remove and Report the file in one line

cat /etc/virtualhosting/mappings/domainmap | awk '{print $3}' | grep -w "site.*" | while read i; do echo $i; sitelookup -s $i >> /backups/report.txt; tar --verify -cpf /backups/$i.tar $i/fst/home $i/fst/var/www $i/fst/var/spool $i/fst/var/lib; du -h -s /backups/$i.tar >> /backups/report.txt; gzip /backups/$i.tar; du -h -s /backups/$i.tar.gz >> /backups/report.txt; scp -P 22 -i /home/user/.ssh/id_rsa /backups/$i.tar.gz user@; rm /backups/$i.tar.gz; done

This command is being added to my upcoming Pro Server Management Book

No comments: