
Code: Select all
#!/bin/bash
if ! grep -q "/mnt/sdb" /etc/mtab ; then
mount /dev/sdb1 -o commit=20 /mnt/sdb || exit 1
fi
# Limit memory usage to 1gb
ulimit -m 1024000
date
for d in bin boot etc lib opt root sbin srv usr var home ; do
echo "Backing up $d"
ionice -c3 nice -n 18 rsync -axHq --delete /$d /mnt/sdb/
done &&
umount /mnt/sdb && hdparm -Y /dev/sdb
date+1ppurka wrote:There is also the gentoo stage4method. Not sure if anyone uses it nowadays.
I've been using stage4 script for quite a while. Works fine.ppurka wrote:There is also the gentoo stage4method. Not sure if anyone uses it nowadays.
Code: Select all
#!/bin/bash
BACKUP_DIR=/mnt/nas
MOUNT_DIR=/mnt/backup
if [ ! -d ${MOUNT_DIR} ]; then
mkdir ${MOUNT_DIR}
fi
mount -o bind / ${MOUNT_DIR}
mount /boot
mount -o bind /boot ${MOUNT_DIR}/boot
cd ${MOUNT_DIR}
tar -cjp ./ -f ${BACKUP_DIR}/backup-${HOSTNAME}-$(date +%Y%m%d).tar.xz
cd ${HOME}
umount /${MOUNT_DIR}/boot
umount /${MOUNT_DIR}
I've used this method some days ago. Not for backing up, for cloning a system. Works fine. Less then two hours for installing a system with all the needed soft.ppurka wrote:There is also the gentoo stage4method. Not sure if anyone uses it nowadays.



Hey, can you give us your usual command list or script you usually use to backup your system?Goverp wrote:If you use ext2/3/4, you might like to try app-arch/dump. It's a command-line tool, also suitable for scripting. Seems fine to me, and when I tried a partial restore some time back, it worked well. I backup to a USB 1TB drive.
... I run dump after "rc single", which isn't quite as good as rebooting to a different OS and mounting all your target disks R/O, but I expect is good enough.
Code: Select all
#!/bin/bash
### Use ext2/3/4 dump utility to backup to an external drive ###
# Locate our configuration file
conf=`dirname $0`/backup.conf
conf=`realpath $conf`
echo "Using $conf"
source $conf
set -ue
### Use the ext2/3/4 dump command for a given file system to a given directory ###
dodump() {
local dir=$1
local fs
if [[ $dir == $rootfs ]] ; then
fs=""
else
fs=$dir
fi
echo
echo "Dumping $dir"
local file=$path/$dir/$name
dump -${level}uy -L $name -f $file.dump /$fs
}
#### Test parameters or die ###
die() {
echo $*
exit 1
}
# Processing starts here
# Check the command line
if [[ $# -eq 0 ]] ; then die "Syntax: backup <level> { <filesystem>... }" ; fi
level=$1
if [[ ! `rc-status --runlevel` == "single" ]] ; then die "You must be in run mode single."
elif [[ ! $level == [0123456789] ]] ; then die "You must specify a numeric dump level."
elif [[ ! ( -d $path && -w $path ) ]] ; then
{
mount $mountpoint
if [[ ! ( -d $path && -w $path ) ]] ; then die "You must mount the dump drive at $mountpoint" ; fi
}
fi
# Get the mount points to dump
shift
if [[ $# -eq 0 ]] ; then
filesystems=$defaultfs
else
filesystems=$*
fi
# Generate dump file names
date=`date +%y%m%d`
if [ $level -eq 0 ] ; then
name="Full-$date" ;
else
name="Incr-$date-$level" ;
fi
echo "Dump label $name"
echo "Dumping filesystems $filesystems"
# For good measure, flush data to disk
sync
# Finally, dump
for fs in $filesystems ; do
dodump $fs
done
# Inform the customer how much space is used on the backup volume
df -h $mountpoint
ls -lh $path/*/$name.dump
exitCode: Select all
# Backup config
# mount point directory to mount the backup drive
mountpoint=/mnt/dumps
# path to backup directory within the backup drive
path=${mountpoint}/acer
# name used for root file system (i.e. "/")
rootfs=slash
# Default list of file systems to dump. Put the smallest first
defaultfs="boot home var ${rootfs}"
Type "rc single" as root, or pass the "single" parameter as part of your kernel boot parameters (from grub or lilo or whatever). To revert, type "rc default". But read on before you try it. I don't think "dump" does what you want.Meet Joe Black wrote:Well, thanks Goverp. I've just read your script. But I need to know how to make rc-status runlevel == single and how to make it normal status again.
No, dump doesn't do that; it creates a backup file containing compressed copies of the data together with its own indexing system that mimics the file system's directory structure. It allows you to recover individual files, directories or the whole file system. But what you appear to want is a simple copy of the file system. The usual command to do that is "dd" from one block device to another. I don't use dd much, so I can't offer more advice.Meet Joe Black wrote: And I want to backup the whole system partition to not file but another partition of the same size on different drive. Is it possible with dump?
Meet Joe Black wrote: I usually use general HDD disks and backup system partition to another disk. In case my primary partiton becomes bad I just change SATA cables and reboot with backuped partition.