Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

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

New cpanel daily backup is creating separate directories for daily backup. This creates problem when I try to user rsync to do an offsite backup since I would like to rsync only latest data. E.g. On backup server I have directory "backup" and on server, from which we are pulling backups I get directories 2013-11-07, 2013-11-08 etc in backup directory. If I backup /backup directory on the server it will use allot more space so I would like to backup only latest directory in backup directory, eg 2013-11-08.

Is there a way to detect latest directory in backup directory and pass that directory name to rsync for backup ?

share|improve this question

dirname=$(ls /backup |sort|tail -1); rsync -avP /backup/$dirname $backup_server:/backup/

share|improve this answer
or $(ls -atr |sort|tail -1) – jijix Nov 13 '13 at 11:03
hmmm... the problem is that ls is taking modification time and not creation time of files. So one time it could work correctly but if on of the directories was accessed/modified then it doesn't give correct result. I tried with ls -ltu and it seems it gives ok result in that way. But, anyone knows any other command that would really take creation time of directory ? – Pracovek Nov 13 '13 at 11:48
Ok, I managed to make som progress. The command would be dirname=$(ls -lt --time=ctime | sed -n 3p | sed 's/^.* //' ); – Pracovek Nov 13 '13 at 13:00
But when I combine that with rsync I get dirname=$(ls -lt --time=ctime | sed -n 3p | sed 's/^.* //' ); rsync -ave /nib/$dirname/ -e 'ssh -pxxx' root@xx.xx.xx.xx:/disk/backup/test/ I get rsync: change_dir "/disk/backup/test" failed: No such file or directory (2) Can anyone see what I'm missing here ? – Pracovek Nov 13 '13 at 13:02

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.