-1

I have a folder /home/software, with some sub folders

/home/software/game
/home/software/photo
/home/software/ebook
...

I want to create tar backup including the date for each sub-folder so I will end up with files like:

game-20151013.tar.gz
photo-20151013.tar.gz
ebook-20151013.tar.gz
...

What's the best way to do that, and to the delete any of those backups that is more than 10 days old?

  • 2
    Have you looked into rsync? It has the compression and pruning that you are looking for. – datUser Oct 13 '15 at 14:35
  • no , i not looking for rsync. – Adam Chan Oct 13 '15 at 14:50
  • 1
    Sounds like you're trying to reinvent the wheel. There are lots of (free and open) backup programs out there that do the job (dar, attic, obnam, ...). – Jan Oct 13 '15 at 15:38
1

Here's a script that does what you have asked for:

ls /home/software/ | while read d
 do
  tar czf "/home/software/$d-$(date +%y%m%d).tar.gz" "/home/software/$d"
 done
find /home/software -type f -name '*.tar.gz' -mtime +10 -exec rm {} \;

or

cd /home/software/
ls | while read d
 do
  tar czf "$d-$(date +%y%m%d).tar.gz" "$d"
 done
find . -type f -name '*.tar.gz' -mtime +10 -exec rm {} \;
  • show the error: tar: Removing leading `/' from member names – Adam Chan Oct 13 '15 at 16:50
  • change directory inside /home/software/ and run commands in place ! see answer editted :) – Jonah Oct 13 '15 at 17:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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