Question

I want to make a backup of each directory in /home separately and each directory tar (backup) files to enter into a specified directory. Under linux ubuntu.

Was it helpful?

Solution 2

To clarify ... I want to make a backup of all directories, for example to /home/user file is named backup-2014.02.02.tar and is located in the directory /home/user /backups. I'm doing a backup of the entire /home directory with the following script:

#!/bin/bash
today=$(date '+%Y.%m.%d')
tar czf /var/backup/backup_"$today".tar.gz /home

Yes, but I want to go to backups in the following way ... If the directory was /home/user file batskup-user-2014.02.04.tar.gz to go to the directory /home/backups

OTHER TIPS

You can do something like this in bash:

for d in */; do short=${d%/}; tar -cvf ${short}.tar $short ;done

Or, more verbosely:

cd                               # go home
for d in */                      # for all directories
do
   short=${d%/}                  # strip off trailing slash
   tar -cvf ${short}.tar $short  # tar up directory into file with same name but ".tar" extension
done

So, if you have doirectories $HOME/Documents and $HOME/Music, you will get 2 tarfiles in your home directory called Documents.tar and Music.tar

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top