Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to merge my incremental backups into the secure folder (which is the main backup folder) in order of date.

Someone has helped with the script to rsync the documents each night via a cron job:

$ for f in `ls -t /var/backups`; do rsync -aL "/var/backups/$f" /var/www/live/documents/; done

Current folder:

backup-2011-07-02  backup-2011-06-27  backup-2011-06-22  backup-2011-06-17
backup-2011-07-06  backup-2011-07-01  backup-2011-06-26  backup-2011-06-21  backup-2011-06-16
backup-2011-07-05  backup-2011-06-30  backup-2011-06-25  backup-2011-06-20  backup-2011-06-15
backup-2011-07-04  backup-2011-06-29  backup-2011-06-24  backup-2011-06-19  backup-2011-06-14
backup-2011-07-03  secure             backup-2011-06-23  backup-2011-06-18

Example folder structure:


In each of these folders is the folder secure in which are the folders and files that need to be merged

I not sure the best way to write a script to merge all the backups in order of date into the secure folder.

Any ideas?

share|improve this question
Not exactly sure what you mean with the "secure" thing, but ls -t is newest first, it seems like you would want oldest first, which would be ls -rt – DerfK Jul 7 '11 at 13:27
@DerfK Secure is the main backup of all files prior to the incremental backups so this holds all the data – Grimlockz Jul 7 '11 at 13:30
It is unclear what results you are trying to obtain. Define "merge". – psusi Jul 7 '11 at 14:17
@psusi Trying to copy all the currents of the backups into one folder doing it in date order so any file that has been change will be over written by the newer file – Grimlockz Jul 7 '11 at 14:19

It is not what you ask for, but you can actually have everyday a full backup with rsync, while it will upload and take as much storage as normal incremental back up. It is done with hard links. I have done a script that automates that and I use it daily on multiple machines. You can grab it with description here:

Note - when backup is done it will update last_full_backup.txt with backup directory. This is in case backup was interrupted.

share|improve this answer

This should do the trick then:

mkdir /var/backups/merged
for f in `ls -t /var/backups/backup-*` ; do cp -an /var/backups/$f/* /var/backups/merged/ ; done
share|improve this answer

Your Answer


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.