How can I mirror / backup a set of files via ncftp?
Last updated: 06/24/2009
Often times it's useful to mirror data from a production server to your local computer, or another server. I've done this for testing purposes, but also for backups. Most hosting providers backup once a day, or less often. If you have data being updated often, and you want it saved, you may want to pull it down multiple times per day. (NOTE: This method does not copy mysql database information.)
Also, just because your host tells you they run backups, doesn't mean they do - or the backups may not work correctly. The time to find out is not after the server crashes, or you accidently delete some files on your site. Your website is your property, and ultimately, you need to take ownership of having backups.
As the question implies, you first need to install ncftp on the system. You can get it here:
where "/home/mirror" is the local directory where you want to store the copied files, and remote_dir1 and remote_dir2 are directories on the ftp server that you want to mirror down.
Save this file and run a "chmod +x mirror.sh" to make it executable.
Run the command to make sure it works: "./mirror.sh"
If you want this to run at regular intervals, you should create a cron entry, such as:
0 18 * * * cd /home/localfiles; ./mirror.sh >/dev/null 2>&1
Obviously, check to make sure things are running smoothly, and rest assured of your local backup.