How to: Backup a website with FTPcopy

When running a website, it is very important to have a backup of all site files, to prepare for any event that may require reloading data (file corruption, moving hosts, etc.). After building my Ubuntu file server, I knew that I had to find a way to mirror this website so files could be recovered if necessary.

I looked at rsync and curlftpfs, but that combination was complex to set up. Soon after, I stumbled on FTPcopy and have found a good solution.

Here is a bash script to automate the process and create a daily mirror of whatever FTP server you want to back up.

  1. Download and install FTPCopy from the repositories.
    sudo apt-get install ftpcopy
  2. Change to a directory that will store the script and open a new text file.
    cd /path/to/directory
    vi ftpbackup
  3. Press i, then copy and paste the following text.
    #!/bin/bash

    USER=username
    HOST="website"
    PASS=password
    REMOTE="public_html/"
    DIR=$(echo "/path/to/backup/$HOST")
    cd $DIR

    # Issue FTPcopy command
    ftpcopy --no-delete -l 1 -u $USER -p $PASS $HOST $REMOTE .

  4. Be sure to change the values for website, storage directory, remote directory, host, username and password.
  5. Save and exit the text file by typing :wq
  6. Make the script executable by typing chmod a+x /path/to/script
  7. Add the script to the crontab so it will be executed on a regular basis. I use Webmin for this type of administration work, but it is possible to use the command line. Use this example to sort out the format. Mine runs daily at 12 AM.

To clarify, this code changes directories into the backup folder, then issues the ftpcopy command. The remote directory of public_html is common on many webservers, but be sure to confirm before running the script. The no-delete option means that files are not removed from the backup if they’ve been removed from the web server. The l option simply means provide feedback of what files are being moved — this can be viewed in your user mail.

After the time has passed for the first time, check the folder where your backups will reside to make sure they are being added as planned.

Tagged with: , , , ,
One comment on “How to: Backup a website with FTPcopy
  1. ZX-14 lady says:

    My whole issue is my lips move when I think.

    Sent from my iPhone 4G

Leave a Reply

Your email address will not be published. Required fields are marked *

*