Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I was curious as to how people normally back up their websites. I normally drag and drop from FTP and use phpmyadmin to download a copy of my databases. I'm sure there's a way where you write a script and have it back up your stuff automatically or upon click, how do people do that? Is it possible to use php to back up stuff?

I have SSH access too.

share|improve this question

migrated from stackoverflow.com Nov 2 '09 at 19:57

This question came from our site for professional and enthusiast programmers.

    
$ tar -cvf 2009-11-03_WWW.tar /web/dir/blah; :) –  Tim Nov 2 '09 at 17:41
    
It would be helpful to know what types of access you have to the web server. e.g. Do you have SSH access? Can you create and run scripts on the server? –  John Gardeniers Nov 2 '09 at 22:40
add comment

5 Answers

up vote 5 down vote accepted
ssh ${USER}@${SERVER} "tar czpf - /path/to/htdocs" > backup_${DATE}.tar.gz

It gets a bit more difficult once databases are involved, but not too much so. (Dump the database to file while keeping an eye on charset encoding, then include the dump into the tarball.)

KISS concept.

share|improve this answer
add comment

You can use a separate file server and cron to dump the database using php / sql through bash then ftp it to another server, on a timed schedule.

Good things to use: mysql dump, cron, sftp, ssh.

share|improve this answer
add comment

I use mysqldump and tar. But the devil is in the details, and it really depends on the specifics of your system. DO make sure you know your encoding: this should be (but isn't always) consistent between your CMS software (e.g. Expression Engine, WordPress, Joomla, whatever), your framework (e.g. PHP), your database (e.g. mysql), and this includes, the tables' individual collation settings, AND the settings of the client, (in this case, mysqldump; to be sure, use the command-line option --default-character-set=utf8, or whatever your encoding is). If your data is encoded one way, and you backup to another encoding, and restore that backup, your data may be subtly corrupted. Everything from; funny characters showing up for double-quotes, hyphens, foreign characters, umlauts and accents, etc - to the worst-case, text strings in serialized fields come back with bad lengths, causing php's unserialize() to fail.

A quicker way of saying all this: TEST your backups! Frequently!

share|improve this answer
add comment

If you have access to your Linux server, you might setup cron/crontab tasks to copy folders and database files over the network/in a safer place.

share|improve this answer
add comment

I use zyxBackup script that supports encryption of final backup file, so you can easily store it on public FTP/SSH server.

The backup method is easy to implement.

share|improve this answer
add comment

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.