LinuxQuestions.org
Help answer threads with 0 replies.
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 06-30-2015, 06:10 AM   #16
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,688

Rep: Reputation: 1259Reputation: 1259Reputation: 1259Reputation: 1259Reputation: 1259Reputation: 1259Reputation: 1259Reputation: 1259Reputation: 1259

I use the "--one-file-system" option which prevents tar from decending through mount point, but does get directory names (but nothing more).

That eliminates having to use multiple excludes (/tmp is a tmpfs mount and is memory resident, as are /dev, /sys, /proc, /run (on Fedora), and /home (separate disk).

My backup script (provided ONLY as an example -use at your own risk):
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...
#------------------------------------------------------------------------
# use os-release information

if [ -f /etc/os-release ]; then
    . /etc/os-release
else
    NAME="Fedora"	# default name
    ID=21		# default version
fi

Release="${NAME}.${ID}"
HOST=`hostname | awk -F . '{print $1}'`

# manually fixed configuration

TARGET="/home/sys"
Base="root boot home"

#------------------------------------------------------------------------
# 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

#------------------------------------------------------------------------
# prepare for the backup

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

# protect the generated tar files

umask 077

# check for archive

if [ ! -d /home/sys/lost+found ]; then
    mount LABEL=archive /home/sys
    if [ $? != 0 ]; then
	echo "can't mount archive filesystem"
	exit 1;
    fi
fi

# verify that the destination exists 

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

#------------------------------------------------------------------------
# Now backup the list of filesystems

for item in ${list}; do
    echo "${item} - "`date +%H:%M:%S`
    case ${item} in
	root)	frm="/"
		xclude=""
#		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`

#------------------------------------------------------------------------
# dismount archive

umount /home/sys

exit
I use this to make system backups. Restoring still needs the boot sectors remade, but that only requires the /boot.

The /boot I have is a separate partition - it also is used by multiple roots, which only works because all systems are Linux, so "dual boot" is rather trivial. Only one version of grub is used to boot both of them. For the most part, there are only two- a "previous distribution", and a "current distribution". And I test a newer distribution in a VM, when finished, I use this to back up the VM root, and restore it to the "previous distribution". This puts the new kernel in /boot, as well as puts the root filesystem in the "previous" root partition. Minor modification to the grub configuration, and I can then use the "previous" as the current, and existing current becomes "previous". This also means I have a full installation to use when restoring the alternate root partition.

I do pick the kernel and initramfs to be put in /boot (rather than restore it, as that could damage the boot code for grub). I realize this isn't as good for grub2, but I haven't switched yet. The problem with grub2 is that the actual configuration is scattered around, and gets rebuilt on each update... which could corrupt the other distributions... But then, I just haven't gotten around to testing that.
 
Old 07-01-2015, 06:27 AM   #17
tearsforhari
Member
 
Registered: Mar 2015
Posts: 79

Original Poster
Rep: Reputation: Disabled
Thanks JPollard. I'll have to do some testing with your script on Ubuntu.
 
Old 07-01-2015, 06:36 AM   #18
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,688

Rep: Reputation: 1259Reputation: 1259Reputation: 1259Reputation: 1259Reputation: 1259Reputation: 1259Reputation: 1259Reputation: 1259Reputation: 1259
The big limitation of the script is that it makes a single tar file. I use it essentially to make an offline snapshot.

Also, since I'm using compression, an error inside a tar file can make the rest of the tar file unusable (as it can't be decompressed very well).

I think I'm at the borderline limit on size, as the partitions I'm backing up (home specifically) are 500GB... And eventually I will have to revisit this and decide on whether it would be better to use a snapshot+incremental backups...
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Back up Debian system to another system?? since1993 Linux - Newbie 1 10-16-2009 02:31 PM
Need to take my system back, and am nervous LovingLinux Linux - Newbie 8 04-17-2009 01:54 AM
Best way to back up system? replica9000 Linux - Software 8 12-17-2007 11:13 AM
How can I back up my system? Jongi Ubuntu 4 04-28-2006 02:14 AM
system back-up powadha Linux - Software 1 12-26-2003 10:03 AM


All times are GMT -5. The time now is 01:39 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration