3

I'm trying to build a backup script that creates a full tarball from my system each night. To do this I followed the tutorial here.

So to test it out I decided to create a manual backup:

tar -cvpzf backup.tar.gz --exclude=/backup.tar.gz --one-file-system / 

When I try to run this command I get the error:

tar: /run/: file is on a different filesystem; not dumped

This results in an exit code of 1. However, I want to run this command in a script and if the returncode is 0 I want to move the output file, otherwise delete it. If I understand correctly from the the tutorial linked above the --one-file-system implies that /run/ is ignored. But why do I get the error then?

For completness sake, the script (WIP) is shown below:

#!/bin/bash

# Location to store backups
STORAGE=/media/storage/backups/full
# Current date
DATE=$(date +"%d.%m.%YT%H.%M")
TAR="$DATE.tar.gz"


# Check if the file already exists. Should never be the case though.
if [ ! -f /tmp/$TAR ]; then

    echo "Changing dir to /"
    cd /
    # Create tarball
    echo "Creating tarball"
    tar -cvpzf /tmp/$TAR --exclude=/tmp/$TAR --one-file-system /
    retcode=$?

    echo "Exit status: $retcode"

    if [ $retcode = 0 ] ; then
        echo "Moving file.."
        # Move the file
        mv /tmp/$TAR $STORAGE/$TAR
        echo "Done!"
    fi
fi
2
  • 1
    You are mistaken; you get the message about the path being ignored because you asked tar to be verbose with the -v switch. That does not cause it to have a non zero exit status. What can cause a non zero exit status however, is when it warns that the contents of a file changed while it was backing it up, which happens when you are trying to backup a filesystem that is in active use. – psusi Dec 2 '14 at 19:00
  • Aha, this makes sense. I was indeed under the presumption that the ignore error was causing the exit code 1. Thank you. If you post this as an answer I will gladly accept. – Christophe De Troyer Dec 2 '14 at 19:01
1

You should declare --one-file-system first before the exclusion rule. There is note from the same guide you followed.

If you want to exclude all other mounts other than the current - by this I mean partitions mounted to directories - then use the --one-file-system option appended before the exclusion rules. This has the effect of stopping tar from crossing into any other mounts in any directory including /mnt or /media.

2
  • That is indeed the case, but I do not explicitly ignore any directories like bin or sys. These ignores are implied by the --one-file-system. So in fact it is a verbatim copy of the command stated in the guide. – Christophe De Troyer Dec 2 '14 at 14:14
  • I was referring to your --exclude=/tmp/$TAR – f01 Dec 2 '14 at 16:44

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.