If you are looking for a solution how to make an automatic copy, backup or synchronized mirror of your files or even a complete website, this article is for you. This solution will copy only new or changed files (incremental copy). So full copy is made only at first run. To make it work you will need ftp or sftp access to server where your files are stored and ssh (or telnet) access to account that you want your files to be mirrored to. To make it work follow this steps:
- Make sure that you have LFTP client installed on your system. You can get it from your Linux distribution repository or get the source from LFTP website and compile like this (if you don't have root access ask your administrator to do it):
wget http://tactical.wiretapped.net/mirrors/lftp/ tar xzvf lftp-4.0.2.tar.gz cd lftp-4.0.2 ./configure make
And as root of your system:
If you won't get any errors during this steps you will have LFTP installed.
- Prepare the directory where you will want to have your mirrored files and change your current dir to it:
mkdir sync cd ./sync
- Create sync file (yoursyncname.lftp) with your favorite text editor and put there this instructions:
open ftp://yourlogin:firstname.lastname@example.org:22 mirror -c /sourcedir/ /local/target/dir exit
Of course you will need to change "yourlogin", "yourpassword" and "sourcedomain.com" with your ftp login details. Please save this file.
- Now create another text file (yoursyncname.sh) that will execute previous commands. Put there this line:
lftp -f /local/target/yoursyncname.lftp
Don't forget to change the path to "yoursyncname.lftp" file!
- Chmod "yoursyncname.sh" to make it executable:
chmod 755 yoursyncname.sh
- Now you can execute "yoursyncname.sh" from command line:
or put it as a cronjob to make regular mirror.
TIP: If you need to exclude any files or subdirectories from being copied from source directory, you may modify "yoursyncname.lftp" to something like this:
open sftp://yourlogin:email@example.com:22 mirror --exclude cgi-bin --exclude stats -c /sourcedir/ /local/target/dir exit