LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Saving root filesystem with tar (https://www.linuxquestions.org/questions/linux-newbie-8/saving-root-filesystem-with-tar-4175490085/)

Mr. Alex 01-04-2014 12:43 AM

Saving root filesystem with tar
 
Hello guys! I am planning to tar my root partition to temporarily move it to another HDD and later back on the old one and untar, so while it's on a new drive I can do some things with the old one. And I wanted to make sure I won't screw it up. Is this set of option (from LiveCD, in a mounted root directory) enough for tar to save and restore all OS files correctly:

Code:

tar cpf sda1.tar *
Or do I need to add some option to handle links or anything else?

grail 01-04-2014 04:04 AM

I think you will need to exclude all temporary file systems (/tmp, /sys, /proc ...)

If you do exclude the above I would suggest placing the tar file on one of them as including within the area being tarred can throw errors (just warnings I think).

As doing the main system you would need to be root, hence -p is already the default

you may also wish to consider compressing it depending on the size of the data and the room on the drive

Mr. Alex 01-04-2014 04:43 AM

Quote:

Originally Posted by grail (Post 5091723)
I think you will need to exclude all temporary file systems (/tmp, /sys, /proc ...)

Will I? As I mentioned, "from LiveCD, in a mounted root directory". So yes, tar file will have to be put somewhere else, but there will be no /proc or /sys dirs/filesystems on sda1 mounted to, say, /mnt when doing it all from some LiveCD. Right?

TobiSGD 01-04-2014 07:14 AM

Quote:

Originally Posted by Mr. Alex (Post 5091730)
Will I? As I mentioned, "from LiveCD, in a mounted root directory". So yes, tar file will have to be put somewhere else, but there will be no /proc or /sys dirs/filesystems on sda1 mounted to, say, /mnt when doing it all from some LiveCD. Right?

Indeed, but you still may to exclude /tmp, unless it is empty anyway.

jpollard 01-04-2014 12:02 PM

I use a shell script for backups - even when on line.

Code:

#!/bin/sh
# backup.sh - a simple backup script creating tar files
# usage:
#        backup.sh [ref]
# where:
#        ref        - reference name of filesystem to backup.
# note:
#        If no ref is specified then all file systems will be backed up.
#        Reference names are one (or more) of root, boot, or home;
#        separated by spaces.
#------------------------------------------------------------------------
# configuration
#        Adding filesystems to the Base list requires modifying
#        the evaluation and the list of real filesystems.
#        This script may be redone as a perl script to simplify this...
#------------------------------------------------------------------------

Base="root boot home"
Release="Fedora16"
TARGET="/home/sys"
HOST="panther"

#------------------------------------------------------------------------
# evaluate options

if [ "$*" == "" ]; then
  list="${Base}"
else
  list="$*"
fi

for item in $list; do
    case $item in
        root);;
        boot);;
        home);;
        *)
          echo "Only one of \"${Base}\" can be used"
          exit 1
        ;;
    esac
done

#------------------------------------------------------------------------
# perform the backup

DATE=`date +"%Y.%m.%d"`

# protect the generated tar files

umask 077

# verify destination exists

if [ ! -d "${TARGET}/${HOST}" ]; then
    mkdir ${TARGET}/${HOST}
fi

if [ ! -d "${TARGET}/${HOST}/${Release}" ]; then
    mkdir ${TARGET}/${HOST}/${Release}
fi

# backup the list of filesystems

for item in ${list}; do

    echo "${item} -"`date +%H:%M:%S`
    case ${item} in
        root)        frm="/"
                xclude=" --exclude /tmp/* --exclude /var/tmp/* --exclude=/home"
                ;;
        boot)        frm="/boot"
                xclude=""
                ;;
        home)        frm="/home"
                xclude="";;
    esac
    tar --one-file-system --selinux --acls --xattrs -z \
        ${xclude} \
        -cf \
                ${TARGET}/${HOST}/${Release}/${item}.${DATE}.tgz ${frm}

done
echo "done  -"`date +%H:%M:%S`

exit

Tar will identify files that change while it is performing a backup... and normally this is not a problem as the files are the log files...

Using the "--one-file-system" eliminates the need to specifically exclude /proc, /sys, and any mounted filesystem as tar will only create an entry for the mountpoint, but not backup any of the files within.


All times are GMT -5. The time now is 06:18 AM.