Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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?
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
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?
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.