Please note that all the SIEpedia's articles address specific issues or questions raised by IAC users, so they do not attempt to be rigorous or exhaustive, and may or may not be useful or applicable in different or more general contexts.
Let's assume we want to have an updated, on a daily basis, copy of the content of some drive or directory "A", to some other drive or directory "B". This can be done automatically and easily by making use of the commands "rsync" and "crontab" (linux), as explained in this recipe step by step:
rsync -avz --force --exclude=lost+found --delete-after /scratch1/ /media/diskusb/scratch1/
cd /home/myusername/somewhere
chmod +x sync.script
Now the script is ready to be executed and perform the syncronization of the "mirror" directory to match the "original" directory. But we still have to tell the system to execute the script every day, for the copy to be kept updated. For example, let's assume we want the "sync" to be done every day at 01:01 (1 am). As this procedure is noiseless, neighbours won't complain. The "rsync" command will, as we are calling it, at 01:01, "update" the copy of the "original" directory kept in the "mirror" directory, as expected. It will only copy again those files in the "original" directory that have changed since the last update (the day before, in this case). Obviously, new files in the "original" directory will also be copied to the "mirror". Also, if some file in the "original" has been deleted since the last update, it will be deleted from the "mirror" as well (to remove this feature, omit the "--delete-after" from the rsync options).
crontab -e
(with this we can edit the file where the system reads the tasks to be performed periodically)
01 01 * * * /home/myusername/somewhere/sync.script
crontab -l
man crontab
for usage info). But it should work on the first shot.
And that's it. Next time it's 01:01 the update of the backup copy will begin. The first time the whole content of the "original" directory will be copied to the "mirror", if it hasn't been done before, and this may take quite a while depending on the volume of data to be copied. Check first that there's enough room in the "mirror" to store a copy of the "original" (use du -h
to see the content of the "original" directory in Kb/Mb/Gb, depending on size). Also, check that you, as user, have write permissions on the "mirror" directory. Every day, after the syncronization is done, the system will e-mail you at "myusername@iac.es", notifying what was done during the process, with the following subject: Cron <myusername@iac.es> /home/myusername/somewhere/sync.script
You can filter these e-mails to a separate e-mail folder, which can be "cleaned" every month, for example. I would suggest to check these e-mails, at least from time to times, to ensure that the copy is being correctly updated. It is possible to disable this e-mail capability from the crontab... but check it out yourself in the "crontab" help, as I don't know how to do it.
You might want to keep also a copy of the erased and/or modified files in your directory, but keeping them in another directory. This could be done with a similar script, using the --backup option, whose execution could also be scheduled in the crontab file. An example:set fecha=`date +'h20%y'`
rsync -au --delete --backup --backup-dir=/media/diskusb/${fecha}/ /scratch1/ /media/diskusb/scratch1/