52 lines
1.4 KiB
Bash
52 lines
1.4 KiB
Bash
#!/bin/bash
|
|
|
|
mirror_rootfs () {
|
|
[[ ! $(command -v rsync) ]] && { echo rsync must be installed to use this function; return 5; }
|
|
dr="--dry-run"
|
|
|
|
dest=$(realpath -s $1)
|
|
rootfs=$(realpath -s "${2:-/}")
|
|
|
|
[ ! -d "$dest" ] && echo destination $dest is not a directory && return 3
|
|
[ ! -d "$rootfs/etc" ] && echo not root filesystem at $rootfs && return 3
|
|
|
|
echo making mirror of root filesystem to
|
|
rfse=rootfs_excludes
|
|
if sudo rsync -axHAWXS $dr --numeric-ids --delete --delete-excluded --force --exclude-from="$(rootfs_excludles)" / /mnt/adrive/nas/@rootfs; then
|
|
echo making mirror of boot partition to /mnt/adrive/nas/@rootfs
|
|
if sudo rsync -axHAWXS $dr --numeric-ids --force --delete /boot/ /mnt/adrive/nas/@boot; then
|
|
echo doit
|
|
else
|
|
echo unable to sync a copy of /boot, aborted backup
|
|
fi
|
|
else
|
|
echo unable to sync a copy of root file system, backkup failed
|
|
fi
|
|
}
|
|
|
|
rootfs_excludes () {
|
|
|
|
local list; local delete
|
|
[[ $1 == "-l" ]] && list=true && shift
|
|
[[ $1 == "-r" ]] && delete=true && shift
|
|
[[ "$1" == "-"* ]] && >&2 echo bad option, aborting && return 1
|
|
rfse=${1:-/tmp/rootfs_excludes.lst}
|
|
[[ $delete ]] && rm $rfse
|
|
cat <<EOF > $rfse
|
|
.[Tt]rash*
|
|
tmp/
|
|
cache/
|
|
log/
|
|
log[s]/
|
|
lost+found
|
|
EOF
|
|
if [[ $list ]];then
|
|
cat $rfse; rm -f $rfse
|
|
else
|
|
echo $rfse
|
|
fi
|
|
}
|
|
|
|
mountpoints () {
|
|
cat /proc/mounts | cut -d ' ' -f2 | sort
|
|
} |