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 ?


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

  • or $(ls -atr |sort|tail -1) – manjiki 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 clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.