0

I'm trying to make a automatic backup via the tar command:

datum=$(date +%F)
buweek=backup_$datum
snap=snapshot_$datum

mkdir /home/user/BackupArchiv/$buweek
tar -czvg /home/user/BackupArchiv/snapshots/$snap -f backupfull /home/user/BackupArchiv/$buweek

For some reason the backup file gets saved in my working directory, next to the script I execute, instead of the given directory.

Edit: Snapshot file now gets created

2
  • 1
    Be careful.You are not using tar but rather gtar and gtar is known to be unable to do incremental restores in case that more than trivial changes appeared between two incremental backups. – schily Oct 8 '20 at 9:46
  • 1
    You don't have to manually edit the title. Just mark an answer as accepted. )) – annahri Oct 9 '20 at 9:27
0

the argument after option -f is the output path and filename of tar command - citing man tar :

Common options:
       -C, --directory=DIR
              change to directory DIR

       -f, --file=ARCHIVE
              use archive file or device ARCHIVE

so your correct command should look like:

tar -czvg /home/user/BackupArchiv/snapshots/$snap -f /home/user/BackupArchiv/$buweek.tar.gz

or maybe switch the paths since it's unclear what you want to backup and where you want it to end up - my example will generate a file:

/home/user/BackupArchiv/backup_2020-10-08.tar.gz for today :)

3
  • Thanks for the help, I've noticed that I confused the last two parameters "backupfull" and the following path. I've changed the command to: "tar -czvg /home/user/BackupArchiv/snapshots/$snap -f /home/user/BackupArchiv/$buweek/backupfull.tag.gz /home" and the backup worked but tar still gave me the helpful response "tar: finished with errorstatus because of previous error" which I'm unsure what it means. – Kävin Oct 9 '20 at 8:07
  • well glad you've fixed it. followup problem is not related to the original question so .. maybe raise another question with complete terminal output I guess. – Roman Spiak Oct 9 '20 at 8:55
  • I asked the new question here: unix.stackexchange.com/questions/613687/… – Kävin Oct 9 '20 at 9:11

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.