View Full Version : [ubuntu] LAMP Backup and Restore

November 19th, 2012, 11:13 PM

I've looked online in several places on backing up a server. And unfortunately it's just not clicking with me. It's a simple LAMP setup with a couple of vhosts. Using PHP, mySQL and wordpress.

I would like to back everything up. The sites, the databases, and all content, config information. And then move it to another host so when it is restored on the new host. Nothing is lost. No user logins or site content.

But I just get confused when looking this information up online in other places. I just need a quick simple solution.

Thank you.

November 19th, 2012, 11:24 PM
I'm not sure about the Wordpress thing, but for the rest, you'd want to use mysqldump to backup the database, rsync to backup the sqldump, html and php pages and Apache config files to a remote location, and then a script on the remote location to restore everything to the correct places and restore the database.

This can all be scripted easily enough in Bash or shell of your choice and run from cron.

Google mysqldump and rsync, or read through the man pages, if you're not sure what to do, ask and I'll try to help further.

November 20th, 2012, 12:31 AM
I would recommend, as the above poster stated, using mysqldump to make a snapshot of the database. Then copy the database files and the Wordpress directory tree to another location using rsync. Wordpress stores uploaded photos and such inside its directory tree instead of inside the database so it's important to back up your Wordpress files on a regular basis.

November 20th, 2012, 12:57 AM
I want to back up all databases. So I found this example online.

mysqldump -u root -p PASSWORD --all-databases > /path/to/dump.sql

However, when I enter that. I get a small file created which just gives usage information.

Usage: mysqldump [OPTIONS] database [tables]
OR mysqldump [OPTIONS] --databases [OPTIONS] DB1 [DB2 DB3...]
OR mysqldump [OPTIONS] --all-databases [OPTIONS]
For more options, use mysqldump --help

Not the dump of the database.

November 20th, 2012, 01:03 AM
Got the dump to work by changing it to:

mysqldump --user=root --password --all-databases > /path/to/all-database.sql

November 20th, 2012, 10:16 AM
mysqldump -u root -p PASSWORD --all-databases > /path/to/dump.sql

I know you got it to work, but the error in the syntax above is the space between -p and PASSWORD, you should have used this:

mysqldump -u root -pPASSWORD --all-databases > /path/to/dump.sql
You seem to have got the idea anyway. Have yo looked at rsync yet? Took me a while to get my head around the syntax, but it's quite easy when you practice it a bit.

November 20th, 2012, 11:00 AM
Careful with that rsync practice. Don't do it in your production environment.
You can sync an empty folder over the website.

November 20th, 2012, 11:39 AM
Careful with that rsync practice. Don't do it in your production environment.
You can sync an empty folder over the website.

Good point, I should have made that clearer, thanks.

November 20th, 2012, 03:59 PM
I strongly recommend use the -n switch with rsync while you are troubleshooting. If you use "rsync -avn source target" you'll see a complete list of the files that would have been transferred so you can check that the paths are correct. Once you are happy with the results, remove the "n" so rsync can do its magic.

November 21st, 2012, 02:34 AM
I did try the rsync to make copies of the files. Looks like it preserves permissions, does it preserve ownership as well?

November 21st, 2012, 01:23 PM
If you use the "-a" switch it preserves both permissions and (numeric) ownerships.

"man rsync" tells you all you need to know.

November 23rd, 2012, 09:42 PM
Thanks all for the assistance. Got both backups to work.