Custom Stage4
From Gentoo Linux Wiki
Contents |
[edit] Introduction
This article will demonstrate how to create a custom stage4 archive. A stage4 archive is an image of your entire root partition. The primary reason to create a stage4 archive is to provide for quick recovery in the event of disk failure. A stage4 archive is the same as a stage3, only you can select the CFLAGS you want to use and what other software you want installed. You can adapt this method to suit your personal uses.
If you want a generic stage4 that you can install on multiple systems, use Genkernel to set up your kernel. This will ensure that on boot, the kernel will work like the one on the livecd. You may also want to use less restrictive CFLAGS (i.e., MCPU instead of MARCH). You may still have to modify /etc/fstab and the USE flags after extracting the stage4, to suit the user.
This article assumes you have already installed Gentoo, if not go to the handbook and do the install first.
This article also assumes that you have already setup any other software you may want to have on your system. For example, on a desktop system you may want X, Xfce4, Sun's JDK, CVS, Emacs, Thunderbird, and Firefox.
[edit] Optional Tar /boot
make a copy of your /boot partition:
Alternatively, you can just mount /boot before you tar everything up. However, there may be problems with this alternate method if you use the stage4 on systems with different hardware configurations.
[edit] Optional Clean up
(If you use an exclude file like the one shown in the next paragraph, this step can be omitted.)
If you are cloning machines make sure you use different /etc/ssh/ssh_host_* keys.
You can follow the Running out of disk space FAQ to free more space.
[edit] The TAR system
Create an exclusion file that tells tar what not to pack into your stage 4 archive. Ending listed directories with /* instead of / will include the directory itself in the tar, but nothing inside the directory, thereby saving you the hassle of recreating them once you've restored.
.bash_history /mnt/* /tmp/* /proc/* /sys/* /dev/* /etc/mtab /etc/ssh/ssh_host_* /usr/src/* /usr/portage/* /path/to/save/at/stage4.tar.bz2
After everything is set up correctly from the previous sections, we will create the archive:
tar options we used:
c - create archive v - verbosely list files processed j - use bzip2 compression f - specify file name X - use the specified exclusion file
tar option we DIDN'T use:
p - preserve file attributes (necessary only during extraction of the tar, not during creation)
Be sure to look at the tar manpage
It will probably take a long time to create the archive depending on how much you have installed. I usually save the archive on a spare disk I have in my system that I use for backups. You can also burn it to a cd or dvd.
If it is too large to fit on a cd you will have to split it up. Large tar files can be split up with 'split'. The parts can be joined later with 'cat'. Read the manpages for these tools before you use them.
Here are some scripts to make this step a little easier.
[edit] Installing from Stage4
- Boot live CD
- Set the system date to UTC and set the BIOS clock # date MMDDHHmmCCYY # hwclock --systohc
- Create partitions, make filesystems and mount filesystems
- Copy your stage4 archive(s) to disk (if it is on another CD type "gentoo docache" at the boot prompt. Then you'll be able to umount/mount other CDs.) # cd /mnt/gentoo # tar -xvjpf stage4.tar.bz2
- If you used the option to copy over your /boot to /bootcpy, then restore /boot from /bootcpy # cp -vR /mnt/gentoo/bootcpy/* /mnt/gentoo/boot/ # rm -rf /mnt/gentoo/bootcpy
- Make a few basic device nodes needed for booting # mknod -m 660 /mnt/gentoo/dev/console c 5 1 # mknod -m 660 /mnt/gentoo/dev/null c 1 3 # mknod -m 600 /mnt/gentoo/dev/initctl p (optional; needed for gensplash) # mknod -m 660 /mnt/gentoo/dev/tty1 c 4 1
- Mount /proc and /dev into the chroot # mount -t proc none /mnt/gentoo/proc # mount -o bind /dev /mnt/gentoo/dev
- Get the latest portage snapshot # cd /mnt/gentoo/usr/ # wget http://gentoo.osuosl.org/snapshots/portage-latest.tar.bz2 # tar xjf portage-latest.tar.bz2
- Chroot into /mnt/gentoo # chroot /mnt/gentoo /bin/bash # env-update; source /etc/profile # touch /etc/mtab
- Make sure the following files are correct for your system
- /boot/grub/grub.conf
- /etc/fstab
- /etc/conf.d/hostname
- /etc/hosts
- /etc/conf.d/net
- Make sure to install your boot loader into the mbr with either grub or lilo
[edit] Partition table tip
To store partition table info:
The first of those saves the mbr and the second will store all partition info (including logical partitions, which aren't part of the mbr).
To restore partition info:
[edit] Grub Tip
After chrooting:
(hd may need to be changed depending on your setup)
[edit] Udev tip
If your eth0 controller doesn't come up after recovery, take a look at /etc/udev/rules.d/70-persistent-net.rules. The issue is that when migrating to a new system, the MAC address for eth0 will probably change if using an embedded NIC, so you need to update eth0 with the correct MAC, which is probably automatically setup as eth1.
# This file was automatically generated by the /lib/udev/write_net_rules
# program, probably run by the persistent-net-generator.rules rules file.
#
# You can modify it, as long as you keep each rule on a single line.
# PCI device 0x8086:0x108c (e1000)
SUBSYSTEM=="net", DRIVERS=="?*", ATTRS{address}=="00:30:48:64:12:2e", NAME="eth0"
# PCI device 0x8086:0x109a (e1000)
SUBSYSTEM=="net", DRIVERS=="?*", ATTRS{address}=="00:30:48:64:12:2f", NAME="eth1"
[edit] Sample Scripts
[edit] backupHome.sh
Small script which is used to make backups of /home. (The /dev/hdX corresponds to the /mnt/tarbackup directory in /etc/fstab.)
| Code: backupHome.sh |
#! /bin/bash
# Backup script for Gentoo Linux
# Author: fdavid
# Date: 2003.11.29.
# Making backup of home partition to cds
# options for the archive
tarOptions="--create --absolute-names --gzip --file"
# name of the archive
archive=/mnt/tarbackup/$(date +%Y%m%d)home.tar.gz
# mount the backup partition
mount /dev/hdaX
sleep 5
# create the archive
tar ${tarOptions} ${archive} /home/;
echo archive is done
# split the archive to cd size
# (use: "cat ${archive}.* >> ${archive}" to join the parts)
split --bytes=700000000 ${archive} ${archive}.
echo splitting is done
# unmount
sleep 5
umount /dev/hdaX
|
Changes to above script:
- lazy_bum removed --preserve-permissions from tarOptions, this is used with EXTRACT only.
[edit] mkstage4.sh
| Code: mkstage4.sh |
#! /bin/bash
## Backup script for Gentoo Linux
## Change Log
## 2006.07.20 by odessit
## Added symmetric & asymmetric encryption options to the script using GnuPG
## to accomodate secure environments
## Date: 2006.03.05 by BrianW
## Initial Script
## Adapted from backupHome.sh by fdavid
## Adapted from mkstage4.sh by nianderson
## This is a script to create a custom stage 4 tarball (System and boot backup)
## I use this script to make a snapshot of my system. Meant to be done weekly in my case
## Please check the options and adjust to your specifics.
echo -=- Starting the Backup Script...
echo -=-
echo -=- Setting the variables...
## The location of the stage 4 tarball.
## Be sure to include a trailing /
stage4Location=/
## The name of the stage 4 tarball.
archive=$stage4Location$(hostname)-stage4.tar.bz2
## Directories/files that will be exluded from the stage 4 tarball.
##
## Add directories that will be recursively excluded, delimited by a space.
## Be sure to omit the trailing /
dir_excludes="/mnt/* /dev /proc /sys /tmp /usr/portage /var/tmp"
##
## Add files that will be excluded, delimited by a space.
## You can use the * wildcard for multiple matches.
## There should always be $archive listed or bad things will happen.
file_excludes="$archive"
##
## Combine the two *-excludes variables into the $excludes variable
excludes="$(for i in $dir_excludes; do if [ -d $i ]; then \
echo -n " --exclude=$i/*"; fi; done) $(for i in $file_excludes; do \
echo -n " --exclude=$i"; done)"
## The options for the stage 4 tarball.
tarOptions="$excludes --create --absolute-names --bzip2 --verbose --totals --file"
echo -=- Done!
echo -=-
## Mounting the boot partition
echo -=- Mounting boot partition, then sleeping for 5 seconds...
mount /boot
sleep 5
echo -=- Done!
echo -=-
## Creating a copy of the boot partition (copy /boot to /bootcpy).
## This will allow the archiving of /boot without /boot needing to be mounted.
## This will aid in restoring the system.
echo -=- Copying /boot to /bootcpy ...
cp -R /boot /bootcpy
echo -=- Done!
echo -=-
## Unmounting /boot
echo -=- Unmounting /boot then sleeping for 5 seconds...
umount /boot
sleep 5
echo -=- Done!
echo -=-
## Creating the stage 4 tarball.
echo -=- Creating custom stage 4 tarball \=\=\> $archive
echo -=-
echo -=- Running the following command:
echo -=- tar ${tarOptions} ${archive} /
tar ${tarOptions} ${archive} /;
echo -=- Done!
## Uncomment this portion to encrypt the stage4 using asymmetric encryption with GnuPG
## To get a list of available ciphers on your machine do #gpg --version
## Note: only aes aes192 aes256 and twofish should be used for large files (~1Gig & larger)
## To Restore: (cat together if split) and #gpg stage4.tar.bz2.gpg
#echo -=- Starting Encryption Process usung asymmetric encryption with a public key -=-
#cd $stage4Location
#gpg --encrypt --batch --recipient [MY_PUB_KEY] --cipher-algo twofish --output $archive.gpg $archive
#rm $archive
#archive=$stage4Location$(hostname)-stage4.tar.bz2.gpg
## Uncomment this portion to encrypt the stage4 using symmetric encryption with GnuPG
## ## To get a list of ciphers on your machine do #gpg --version
## Note: only aes aes192 aes256 and Twofish should be used for large files (~1 gig & larger)
## To Restore: (cat together if split) and #gpg stage4.tar.bz2.gpg
#echo -=- Starting Encryption Process usung symmetric encryption with a password -=-
#cd $stage4Location
#pass=PLEASE_CHANGE_ME_I_BEG_YOU!
#echo $pass | gpg --batch --cipher-algo twofish --passphrase-fd 0 --symmetric $archive
#rm $archive
#archive=$stage4Location$(hostname)-stage4.tar.bz2.gpg
## Split the stage 4 tarball in cd size tar files.
## To combine the tar files after copying them to your
## chroot do the following: "cat *.tar.bz2 >> stage4.tar.bz2".
## or if encrypted do the following: "cat *.tar.bz2.gpg >> stage4.tar.bz2.gpg".
## Uncomment the following lines to enable this feature.
#echo -=- Splitting the stage 4 tarball into CD size tar files...
#split --bytes=700000000 ${archive} ${archive}.
#echo -=- Done!
## Removing the directory /bootcpy.
## You may safely uncomment this if you wish to keep /bootcpy.
echo -=- Removing the directory /bootcpy ...
rm -rf /bootcpy
echo -=- Done!
echo -=-
## This is the end of the line.
echo -=- The Backup Script has completed!
|
Changes to above script:
- Milos Ivanovic
- Removed --preserve-permissions from tarOptions. This is used with EXTRACT only!
- odessit
- Added Public Key and Password encryption methods using GnuPG
- Added instructions how to merge split files
- Added changelog-like comments to the top of the script.
- BrianW
- Cleaned up the script a bit.
- Made it so the --exclude= for the archive doesn't have to be edited if you modify $stage4Location
- Added --exclude=/var/tmp/*
- Added --verbose to the tar options
- Added code to remove /bootcpy
- Moved the --exclude directories/files out of $tarOptions into their own variable's (thanks kamilian)
[edit] installstage4.sh
Here is a little script to install from a stage4 created by either of the #backupHome.sh and #mkstage4.sh. (Limited testing reported by rpcyan thanks please continue testing) should work though. A few changes were made by rpcyan to get the install script working correctly Please contact me with comments or improvements. nianderson
| Code: installstage4.sh |
#! /bin/bash # Backup script for Gentoo Linux # Author: nianderson # Date: 2004.09.15. # #Used to install a stage4 created with mkstage4.sh #assumes you have already partitioned and formated your drive #assumes your booted from gentoo live cd #assumes you already decrypted your *.gpg archive (#gpg stage4.tar.bz2.gpg) #Define Disk layout #if using ide disks use hdax if using scsi use sdax rootPartition=/dev/sda3 bootPartition=/dev/sda1 #where to mount the disk partitions mntRootPartition=/mnt/gentoo mntBootPartition=/mnt/gentoo/boot #URL of stage4 #I put a copy of the tar on a webserver so i can #easily get it when a reinstall is needed urlToStage4=http://domain.com/ stage4=hostname-stage4.tar.bz2 #mount root partition echo mounting root partition $rootPartition to $mntRootPartition mount $rootPartition $mntRootPartition sleep 5 echo #not sure about this part yet #wget the stage4 to the mounted root partition cd $mntRootPartition echo wget $urlToStage4$stage4 to $mntRootPartition wget $urlToStage4$stage4 sleep 5 #untar the stage4 echo extract stage4 tar xjpf $stage4 sleep 5 echo #mount boot partiton echo mounting $bootPartition to $mntBootPartition mkdir $mntbootPartition mount $bootPartition $mntBootPartition sleep 5 echo #copy boot copy back to boot echo copy bootcpy back to boot cp -R $mntRootPartition/bootcpy $mntBootPartition sleep 5 #remove stage4 file rm -rf $mntRootPartition/$stage4 echo you need to check your fstab and install grub or lilo then echo all should be well echo Removing bootcpy rm -rf /bootcpy echo Enjoy |
[edit] makestage4.sh
For explanation and further information refer to the Gentoo Forums Post. A howto (Wiki) and the latest version of the script can be found here.
| Code: mkstage4.sh |
#!/bin/bash
# Backup script for Gentoo Linux
#
# mkstage4.sh is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# mkstage4.sh is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# Copyright: Reto Glauser aka blinkeye
# Mailto: stage4 at blinkeye dot ch
# Homepage: http://blinkeye.ch
# Forum post: http://forums.gentoo.org/viewtopic-t-312817.html
# Date: 2009-04-02
version=v3.7
basename=`basename $0`
find=/usr/bin/find
tar=/bin/tar
# these are the commands we actually need for the backup
command_list=(cut date echo $find grep hostname mount sh split $tar umount uname which)
# verify that each command we use exists. if one can't be found use $PATH and make a suggestion if possible.
for command in ${command_list[@]}; do
if [ ! -x "`which $command 2>&1`" ]; then
echo -e "\nERROR: $command not found! "
base=`basename $command`
if [ "`which $base 2>&1 | grep "no \`basename $command\` in"`" != "" ]; then
echo -e "ERROR: $base is not in your \$PATH."
fi
exit -1
fi
done
help="\nUsage:\n\nsh `basename $0` [[-v]|[--verbose]] [[-s]|[--split]] \n\nTo run the script NOT in verbose mode comes in handy if you want to see only the errors that occur during the backup.\n"
# Defaults to creating one tarball
tar_output="--file"
# split command
split_options="--suffix-length=1 --bytes=685m"
# options for the tar command
tarOptions=" --preserve-permissions --create --absolute-names --totals --ignore-failed-read"
# where to put the stage4
stage4Location=/mnt/backups/stage4
# name prefix
stage4prefix=`hostname`-stage4-`date +\%Y.\%m.\%d`
# patterns which should not be backed up (like iso files).
# example: default_exclude_pattern="*.iso *.divx"
# These pattern count only for files NOT listed in the $custom_include_list.
default_exclude_pattern=""
# these files/directories are always excluded. don't add trailing slashes.
# don't touch it unless you know what you are doing!
# /var/db and /var/cache/edb are intentionally added here. they are listed
# in $default_include_folders
default_exclude_list="
/dev
/lost+found
/mnt
/proc
/sys
/tmp
/usr/portage
/usr/src
/var/log
/var/tmp
/var/db
/var/cache/edb
$stage4Location
`echo $CCACHE_DIR`"
# files/devices/folders, which need to be backed up (preserve folder structure).
# don't touch it unless you know what you are doing! no recursive backup of folders.
# use $default_include_folders instead.
default_include_files="
/dev/null
/dev/console
/home
/mnt
`find /mnt -name .keep`
/proc
/sys
/tmp
/usr/portage
/usr/src
/var/log/emerge.log
/usr/src/linux-`uname -r`/.config"
# folders, which need to be backed up recursively on every backup.
# don't touch it unless you know what you are doing! the reason for this
# variable is that some users add /var to the $default_exclude_list. here
# we ensure that portage's memory is backed up in any case.
default_include_folders="
/var/db"
# IMPORTANT: A minimal backup will EXCLUDE files/folders listed here. A custom backup will
# include/exclude these files/folders depening on your answer.
custom_include_list="
/home/*
/usr/src/linux-`uname -r`"
# add files/folders here which are subfolders of a folder listed in $custom_include_list which should NOT
# be backed up. eg.
#custom_exclude_list="/home/foo/mp3 /home/foo/downloads /home/foo/.*"
custom_exclude_list=""
# Only files/folders within the $custom_include_list are checked against these patterns
# custom_exclude_pattern="*.mp3 *.iso"
custom_exclude_pattern=""
# the find_command
find_command="$find /*"
# don't backup anything which matches pattern listed in $default_exclude_pattern
for pattern in $default_exclude_pattern; do
find_command="$find_command -not -name $pattern"
done
# assemble the find_command
function find_files()
{
for folder in $default_exclude_list; do
find_command="$find_command -path $folder -prune -o"
done
find_command="$find_command -print"
for i in $default_include_files; do
find_command="echo $i; $find_command"
done
for i in $default_include_folders; do
if [ -d $i ]; then
find_command="$find $i; $find_command"
else
find_command="echo $i; $find_command"
fi
done
}
# check the exclude/include variables for non-existing entries
function verify()
{
for i in $1; do
if [ ! -e "`echo "$i" | cut -d'=' -f2 | cut -d'*' -f1`" -a "$i" != "/lost+found" -a "$i" != "$stage4Location" ]; then
echo "ERROR: `echo "$i" | cut -d'=' -f2` not found! Check your "$2
exit 0
fi
done
}
# check input parameters
while [ $1 ]; do
case $1 in
"-h" | "--help")
echo -e $help
exit 0;;
"-v" | "--verbose")
verbose=$1;;
"-s" | "--split")
tar_output="--split";;
"");;
*)
echo -e $help
exit 0;;
esac
shift
done
echo ""
# check folder/files listed in $default_exclude_list exist
verify "$default_exclude_list" "\$default_exclude_list"
# check files listed in $default_include_files exist
verify "$default_include_files" "\$default_include_files"
# check folder listed in $default_include_folders exist
verify "$default_include_folders" "\$default_include_folders"
#check folder listed in $custom_include_list exist
verify "$custom_include_list" "\$custom_include_list"
#check folder listed in $custom_exclude_list exist
verify "$custom_exclude_list" "\$custom_exclude_list"
# print out the version
echo -e "\nBackup script $version"
echo -e "=================="
# how do you want to backup?
echo -e "\nWhat do you want to do? (Use CONTROL-C to abort)\n
Fast (tar.gz):
(1) Minimal backup
(2) Interactive backup
Best (tar.bz2):
(3) Minimal backup
(4) Interactive backup\n"
while [ "$option" != '1' -a "$option" != '2' -a "$option" != '3' -a "$option" != '4' ]; do
echo -en "Please enter your option: "
read option
done
case $option in
[1,3])
stage4Name=$stage4Location/$stage4prefix-minimal.tar;;
[2,4])
stage4Name=$stage4Location/$stage4prefix-custom.tar
for folder in $custom_include_list; do
echo -en "\nDo you want to backup" `echo "$folder" | cut -d'=' -f2`"? (y/n) "
read answer
while [ "$answer" != 'y' -a "$answer" != 'n' ]; do
echo -en "Do you want to backup" `echo "$folder" | cut -d'=' -f2`"? (y/n) "
read answer
done
if [ "$answer" == 'n' ]; then
find_command="$find_command -path $folder -prune -o"
else
custom_find="$find $folder"
for i in $custom_exclude_pattern; do
custom_find="$custom_find -name $i -o"
done
for i in $custom_exclude_list; do
custom_find="$custom_find -path $i -prune -o"
done
find_command="$custom_find -print; $find_command"
fi
done ;;
esac
# add $custom_include_list to the $default_exclude_list as we assembled
# $custom_find with $custom_include_list already.
default_exclude_list="$default_exclude_list $custom_include_list"
case $option in
[1,2])
stage4postfix="gz"
zip="--gzip";;
[3,4])
stage4postfix="bz2"
zip="--bzip2";;
esac
# mount boot
echo -e "\n* mounting boot"
mount /boot >/dev/null 2>&1
# find the files/folder to backup
find_files
find_command="($find_command)"
# create the final command
if [ "$tar_output" == "--file" ]; then
tar_command="$find_command | $tar $zip $tarOptions $verbose --file $stage4Name.$stage4postfix --no-recursion -T -"
else
tar_command="$find_command | $tar $zip $tarOptions $verbose --no-recursion -T - | split $split_options - "$stage4Name.$stage4postfix"_"
fi
if [ "$verbose" ]; then
echo -e "\n* creating the stage4 in $stage4Location with the following command:\n\n"$tar_command
fi
# everything is set, are you sure to continue?
echo -ne "\nDo you want to continue? (y/n) "
read answer
while [ "$answer" != 'y' ] && [ "$answer" != 'n' ]; do
echo -ne "Do you want to continue? (y/n) "
read answer
done
if [ "$answer" == 'y' ]; then
# check whether the file already exists.
if [ "$tar_output" == "--split" ]; then
overwrite="`ls "$stage4Name.$stage4postfix"_* 2>&1 | grep -v 'No such file'`"
else
overwrite="$stage4Name.$stage4postfix"
fi
if [ -a "`echo "$overwrite" | grep "$overwrite" -m1`" ]; then
echo -en "\nDo you want to overwrite $overwrite? (y/n) "
read answer
while [ "$answer" != 'y' ] && [ "$answer" != 'n' ]; do
echo -en "Do you want to overwrite $overwrite? (y/n) "
read answer
done
if [ "$answer" == 'n' ]; then
echo -e "\n* There's nothing to do ... Exiting"
exit 0;
fi
fi
# if necessary, create the stage4Location
if [ ! -d "$stage4Location" ] ; then
echo "* creating directory $stage4Location"
mkdir -p $stage4Location
fi
echo -e "\n* Please wait while the stage4 is being created.\n"
# do the backup.
sh -c "$tar_command"
# finished, clean up
echo -e "\n* stage4 is done"
echo "* umounting boot"
umount /boot >/dev/null 2>&1
# Integrity check
echo -e "* Checking integrity"
if [ "$zip" == "--gzip" ]; then
zip="gzip"
else
zip="bzip2"
fi
if [ "$tar_output" == "--split" ]; then
if [ "`cat "$stage4Name.$stage4postfix"_*"" | $zip --test 2>&1`" != "" ]; then
echo -e "* Integrity check failed. Re-run the script and check your hardware."
exit -1
fi
else
if [ "`$zip --test $stage4Name.$stage4postfix 2>&1`" != "" ]; then
echo -e "* Integrity check failed. Re-run the script and check your hardware."
exit -1
fi
fi
# everything went smoothly
echo -e "* Everything went smoothly. You successfully created a stage4."
else
echo -e "\n* There's nothing to do ... Exiting"
fi
|
[edit] /sbin/mkstage4
Here an alternative mkstage4 shell script
| Code: /sbin/mkstage4 |
#!/bin/sh
# checks if run as root
if ! [ "`whoami`" == "root" ]
then
echo "`basename $0`: must be root."
exit 1
fi
# checks for correct cmdline usage
if [ "$#" == "0" ]
then
echo "`basename $0`: too few arguments."
echo "syntax: \$ `basename $0` [-q|--quiet] <backup-filename> [custom-tar-options]"
echo "-q, --quiet: activates quiet mode (no confirmation)."
exit 1
fi
# checks for quiet mode (no confirmation)
if [ "$1" == "-q" ] || [ "$1" == "--quiet" ]
then
shift
AGREE="yes"
fi
# determines if filename was given with relative or absolute path
if [ "`echo $1 | grep -c '\/'`" -gt "0" ] && \
[ "`echo $1 | grep -c '^\/'`" -gt "0" ]
then
STAGE4_FILENAME="$1"
else
STAGE4_FILENAME="`pwd`/$1"
fi
# misc vars initialization block
shift;OPTIONS="$@"
EXCLUDES="\
--exclude=/dev/* \
--exclude=/proc/* \
--exclude=/sys/* \
--exclude=/tmp/* \
--exclude=/usr/portage \
--exclude=/var/tmp/* \
--exclude=/var/lock/* \
--exclude=/var/log/* \
--exclude=/var/run/* \
--exclude=.bash_history \
--exclude=lost+found \
--exclude=$STAGE4_FILENAME"
TAR_OPTIONS="-cjpP --ignore-failed-read -f"
# if not in quiet mode, this message will be displayed
if [ "$AGREE" != "yes" ]
then
echo "Are you sure that you want to make a complete system-backup now?"
echo ""
echo "NOTE: external filesystems which should not be saved must be"
echo "unmounted before backing up or their mountpoints excluded per cmdline."
echo "example: \$ `basename $0` /my-backup.tar.bz2 --exclude=/mnt/samba/* ..."
echo ""
echo "WARNING: since all data is saved by default the user should exclude all"
echo "security- or privacy-related files and directories manually per cmdline."
echo "example: \$ `basename $0` /my-backup.tar.bz2 --exclude=/etc/ssh/ssh_host*"
echo ""
echo -e "COMMAND LINE PREVIEW:\n\$ tar $TAR_OPTIONS $STAGE4_FILENAME / $EXCLUDES $OPTIONS"
echo ""
echo -n "Type \"yes\" to continue or anything else to quit: "
read AGREE
fi
# start stage4 creation
if [ "$AGREE" == "yes" ]
then
tar $TAR_OPTIONS $STAGE4_FILENAME / $EXCLUDES $OPTIONS
fi
exit 0
|
[edit] Credits
Original Forum Post by allucid.
Up-to-Date Forum Thread link you to Blinkeye's Wiki by Blinkeye
[edit] See also
[edit] Feedback
For feedback/comments, please use the Discussion page.