add rclone function
parent
66bc374668
commit
ca8ab01a43
|
@ -1,29 +1,67 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
mirror_rootfs () {
|
mirror_rootfs () {
|
||||||
|
local boot; local dest; local rootfs; local opts
|
||||||
[[ ! $(command -v rsync) ]] && { echo rsync must be installed to use this function; return 5; }
|
[[ ! $(command -v rsync) ]] && { echo rsync must be installed to use this function; return 5; }
|
||||||
dr="--dry-run"
|
opts=" --dry-run"
|
||||||
|
[[ $1 == "--run" ]] && opts="" && shift
|
||||||
|
[[ $1 == "-v" ]] && opts+=" -v" && shift
|
||||||
|
[[ $1 == "-o" ]] && opts+=" $2" && shift
|
||||||
|
|
||||||
dest=$(realpath -s $1)
|
dest=$(realpath -s $1)
|
||||||
rootfs=$(realpath -s "${2:-/}")
|
rootfs=$2
|
||||||
|
|
||||||
[ ! -d "$dest" ] && echo destination $dest is not a directory && return 3
|
[ ! -d "$dest" ] && echo destination $dest is not a directory && return 3
|
||||||
[ ! -d "$rootfs/etc" ] && echo not root filesystem at $rootfs && return 3
|
[ ! -d "$rootfs/etc" ] && echo not root filesystem at $rootfs && return 3
|
||||||
|
|
||||||
echo making mirror of root filesystem to
|
echo making mirror of root filesystem at ${rootfs:-/} to $dest/rootfs
|
||||||
rfse=rootfs_excludes
|
#TODO if destination is btrfs then make snapshot otherwise make directory
|
||||||
if sudo rsync -axHAWXS $dr --numeric-ids --delete --delete-excluded --force --exclude-from="$(rootfs_excludles)" / /mnt/adrive/nas/@rootfs; then
|
sudo btrfs subvol create $dest/rootfs >/dev/null
|
||||||
echo making mirror of boot partition to /mnt/adrive/nas/@rootfs
|
if sudo rsync -axHAWXS $opts --info=progress2 --numeric-ids --delete --delete-excluded --force --exclude-from="$(rootfs_excludes)" ${rootfs:-/} $dest/rootfs ; then
|
||||||
if sudo rsync -axHAWXS $dr --numeric-ids --force --delete /boot/ /mnt/adrive/nas/@boot; then
|
echo root parition mirror was made to $dest/rootfs
|
||||||
echo doit
|
boot=$rootfs/boot
|
||||||
|
[[ ! $(mountpoint $boot) ]] && boot=$rootfs/boot/efi
|
||||||
|
[[ ! $(mountpoint $boot) ]] && echo neither $rootfs/boot nor $boot are mountpoints, no boot parition to mirror && return 2
|
||||||
|
echo making mirror of boot $boot partition to $dest$boot
|
||||||
|
sudo btrfs subvol create $dest$boot >/dev/null
|
||||||
|
if sudo rsync -aHAWXS $opts --info=progress2 --numeric-ids --force --delete $boot/ $dest$boot; then
|
||||||
|
echo boot partion is mirrored
|
||||||
else
|
else
|
||||||
echo unable to sync a copy of /boot, aborted backup
|
echo unable to sync a copy of $boot, aborted backup
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo unable to sync a copy of root file system, backkup failed
|
echo unable to sync a copy of root file system, backkup failed
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rclone () {
|
||||||
|
local boot; local dest; local src; local opts
|
||||||
|
[[ ! $(command -v rsync) ]] && { echo rsync must be installed to use this function; return 5; }
|
||||||
|
opts=" --dry-run"
|
||||||
|
[[ $1 == "--run" ]] && opts="" && shift
|
||||||
|
[[ $1 == "-v" ]] && opts+=" -v" && shift
|
||||||
|
[[ $1 == "-o" ]] && opts+=" $2" && shift
|
||||||
|
|
||||||
|
src=$(realpath $1)
|
||||||
|
dest=$(realpath $2)
|
||||||
|
mkdir -p $dest >/dev/null
|
||||||
|
echo making clone/mirror of $src to $dest
|
||||||
|
|
||||||
|
if [ "$(ls -A $dest)" ]; then
|
||||||
|
echo WARNING: $dest is not empty but will be erased!, be sure before using --run
|
||||||
|
# TODO RUN CONFIRM
|
||||||
|
# if [[ $opt == *"--run"* ]]; then
|
||||||
|
fi
|
||||||
|
# if sudo rsync -axHAWXS $opts --info=progress2 --numeric-ids --delete --delete-excluded --force $src/ $dest/ ; then
|
||||||
|
cmd="sudo rsync -axHAWXS $opts --info=progress2 --numeric-ids --delete --force $src/ $dest/"
|
||||||
|
echo "$cmd"
|
||||||
|
if $cmd ; then
|
||||||
|
echo mirror/clone was successful
|
||||||
|
else
|
||||||
|
echo unable to make the clone
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
rootfs_excludes () {
|
rootfs_excludes () {
|
||||||
|
|
||||||
local list; local delete
|
local list; local delete
|
||||||
|
@ -31,6 +69,7 @@ local list; local delete
|
||||||
[[ $1 == "-r" ]] && delete=true && shift
|
[[ $1 == "-r" ]] && delete=true && shift
|
||||||
[[ "$1" == "-"* ]] && >&2 echo bad option, aborting && return 1
|
[[ "$1" == "-"* ]] && >&2 echo bad option, aborting && return 1
|
||||||
rfse=${1:-/tmp/rootfs_excludes.lst}
|
rfse=${1:-/tmp/rootfs_excludes.lst}
|
||||||
|
touch $rfse
|
||||||
[[ $delete ]] && rm $rfse
|
[[ $delete ]] && rm $rfse
|
||||||
cat <<EOF > $rfse
|
cat <<EOF > $rfse
|
||||||
.[Tt]rash*
|
.[Tt]rash*
|
||||||
|
|
Loading…
Reference in New Issue