Linux Tar command help

Associate
Joined
7 Nov 2008
Posts
1,406
Location
Edinburgh, Scotland
Hi there,

Currently writing a script file that backs up and restores files.
Backup is working fine, but my restore command is giving me grief!

What im trying to achieve is the restore a backup from the backups folder to the root folder , ~, and rename the restored file to "Restore-[Backupname]"

This is the command currently but i think my the arrangement is all wrong, help!

Code:
tar -xvf ~/scriptfiles/backups/"$filename" $filename >> ~/scriptfiles/logfiles/"Restore-$filename"

Its probably total rubbish now as iv been messing with it to try and make it work.
I think i have the name of the file, the destination and the destination name messed up.

Thanks in advance!
Em
 
You were very close :) you just have to tell tar to extract to stdout rather than to disk.

This should work, probably want just a > rather than >> and use $HOME rather than a ~ or just hardcode the directory.

Code:
tar -xOvf "$HOME/scriptfiles/backups/$filename" "$filename" > "$HOME/scriptfiles/logfiles/Restore-$filename"
 
How would I get it to extract the backup to /root/ ?

Currently its extracting to backups,

/root/
scriptfiles/
backups

How would i use stdout?

Am i right in saying this section of code is to define where the extraction goes?
Code:
tar -xOvf "$HOME/scriptfiles/backups/$filename"
And then "$filename" is telling the tar command what the file is call that should be extracted?

Thanks very much :D
 
Back
Top Bottom