LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 01-04-2014, 12:43 AM   #1
Mr. Alex
Senior Member
 
Registered: May 2010
Distribution: No more Linux. Done with it.
Posts: 1,238

Rep: Reputation: Disabled
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?
 
Old 01-04-2014, 04:04 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
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
 
Old 01-04-2014, 04:43 AM   #3
Mr. Alex
Senior Member
 
Registered: May 2010
Distribution: No more Linux. Done with it.
Posts: 1,238

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by grail View Post
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?
 
Old 01-04-2014, 07:14 AM   #4
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
Blog Entries: 2

Rep: Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886
Quote:
Originally Posted by Mr. Alex View Post
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.
 
Old 01-04-2014, 12:02 PM   #5
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
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.

Last edited by jpollard; 01-04-2014 at 12:05 PM.
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] compress with tar without saving full paths razor7 Linux - Newbie 6 11-14-2016 04:57 AM
tar tar cvf - . | (cd /root/; tar xvf -) ewt3y Linux - General 10 02-19-2014 10:55 AM
[SOLVED] how can i remount root filesystem as read/write after modify readonly-root file jcwkyl Linux - Newbie 3 12-21-2010 10:40 PM
Saving the total bytes written using TAR to a textfile Berris.Oliver Linux - Newbie 2 02-24-2009 02:25 AM
Encrypted Root Filesystem HOWTO and /dev filesystem tmillard Linux From Scratch 0 10-18-2004 03:58 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:48 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration