dsnap-sync: function updates
* verify_structure() stat function evaluation cleanup * get_disk_info() cmd alingnment Signed-off-by: Ralf Zerres <ralf.zerres@networkx.de>
This commit is contained in:
@@ -347,12 +347,19 @@ get_disk_infos () {
|
|||||||
|
|
||||||
# get mounted BTRFS infos
|
# get mounted BTRFS infos
|
||||||
if [ "$($ssh findmnt --noheadings --nofsroot --mountpoint / --output FSTYPE)" = "btrfs" ]; then
|
if [ "$($ssh findmnt --noheadings --nofsroot --mountpoint / --output FSTYPE)" = "btrfs" ]; then
|
||||||
# root filesystem is never seen as valid target location
|
# root filesystem is excluded as a valid target location
|
||||||
exclude_uuid=$($ssh findmnt --noheadings --nofsroot --types btrfs --mountpoint / --output UUID)
|
exclude_uuid=$($ssh findmnt --noheadings --nofsroot --mountpoint / --output UUID)
|
||||||
disk_uuids=$($ssh findmnt --noheadings --nofsroot --types btrfs --output UUID,TARGET --list | grep -v $exclude_uuid | awk '{print $1}')
|
disk_uuids=$($ssh findmnt --noheadings --nofsroot --types btrfs --output UUID,TARGET --list \
|
||||||
disk_targets=$($ssh findmnt --noheadings --nofsroot --types btrfs --output UUID,TARGET --list | grep -v $exclude_uuid | awk '{print $2}')
|
| grep -v $exclude_uuid \
|
||||||
fs_options=$($ssh findmnt --noheadings --nofsroot --types btrfs --output UUID,OPTIONS --list | grep -v $exclude_uuid | awk '{print $2}')
|
| awk '{print $1}')
|
||||||
|
disk_targets=$($ssh findmnt --noheadings --nofsroot --types btrfs --output UUID,TARGET --list \
|
||||||
|
| grep -v $exclude_uuid \
|
||||||
|
| awk '{print $2}')
|
||||||
|
fs_options=$($ssh findmnt --noheadings --nofsroot --types btrfs --output UUID,OPTIONS --list \
|
||||||
|
| grep -v $exclude_uuid \
|
||||||
|
| awk '{print $2}')
|
||||||
else
|
else
|
||||||
|
# target location is not mounted as root
|
||||||
disk_uuids=$($ssh findmnt --noheadings --nofsroot --types btrfs --output UUID --list)
|
disk_uuids=$($ssh findmnt --noheadings --nofsroot --types btrfs --output UUID --list)
|
||||||
disk_targets=$($ssh findmnt --noheadings --nofsroot --types btrfs --output TARGET --list)
|
disk_targets=$($ssh findmnt --noheadings --nofsroot --types btrfs --output TARGET --list)
|
||||||
fs_options=$($ssh findmnt --noheadings --nofsroot --types btrfs --output UUID,OPTIONS --list | awk '{print $2}')
|
fs_options=$($ssh findmnt --noheadings --nofsroot --types btrfs --output UUID,OPTIONS --list | awk '{print $2}')
|
||||||
@@ -1926,22 +1933,18 @@ verify_snapper_structure () {
|
|||||||
"$backup_root" "$remote_host"
|
"$backup_root" "$remote_host"
|
||||||
|
|
||||||
# create the non existing remote BTRFS subvolume for given snapshot
|
# create the non existing remote BTRFS subvolume for given snapshot
|
||||||
cmd="$ssh stat --format %i $backup_root/$snapper_snapshot 2>/dev/null"
|
cmd="$ssh btrfs subvolume create $backup_root/$snapper_snapshot 1>/dev/null"
|
||||||
if [ -z $(eval $cmd) ]; then
|
$(eval $cmd) || \
|
||||||
cmd="$ssh btrfs subvolume create $backup_root/$snapper_snapshot 1>/dev/null"
|
die "Creation of BTRFS subvolume $remote_host: $backup_root failed."
|
||||||
$(eval $cmd) || \
|
cmd="$ssh chmod 0700 $backup_root 1>/dev/null"
|
||||||
die "Creation of BTRFS subvolume $remote_host: $backup_root failed."
|
$(eval $cmd) || \
|
||||||
cmd="$ssh chmod 0700 $backup_root 1>/dev/null"
|
die "Changing the directory mode for '$backup_root' on '$remote_host'."
|
||||||
$(eval $cmd) || \
|
|
||||||
die "Changing the directory mode for '$backup_root' on '$remote_host'."
|
|
||||||
fi
|
|
||||||
else
|
else
|
||||||
printf "dryrun: Would create new snapper configuration from template %s ...\n" "$snapper_subvolume_template"
|
printf "dryrun: Would create new snapper configuration from template %s ...\n" "$snapper_subvolume_template"
|
||||||
printf "dryrun: Would create new snapper subvolume '%s' ...\n" "$backup_root/$snapper_snapshot"
|
printf "dryrun: Would create new snapper subvolume '%s' ...\n" "$backup_root/$snapper_snapshot"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
cmd="$ssh stat --format %i $backup_root 2>/dev/null"
|
if [ $ret -ne 256 ]; then
|
||||||
if [ $(eval $cmd) -ne 256 ]; then
|
|
||||||
die "%s needs to be a BTRFS subvolume. But given %s is just a directory.\n" \
|
die "%s needs to be a BTRFS subvolume. But given %s is just a directory.\n" \
|
||||||
"$snapper_config" "$backup_root"
|
"$snapper_config" "$backup_root"
|
||||||
fi
|
fi
|
||||||
@@ -2049,17 +2052,22 @@ verify_snapper_structure () {
|
|||||||
die "Can't create snapshot dir on target."
|
die "Can't create snapshot dir on target."
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
if [ -z "$remote" ]; then
|
cmd="$ssh stat --format %i $backup_root/$snapper_snapshots/$snapper_id/snapshot 2>/dev/null"
|
||||||
printf "${RED}Cancel snapshot creation${NO_COLOR}: Former snapshot with id ${GREEN}'%s'${NO_COLOR} already exist in ${BLUE}'%s'${NO_COLOR}\n" \
|
ret=$(eval $cmd)
|
||||||
"$snapper_id" "$backup_root/$snapper_snapshots"
|
if [ $? -eq 0 ] && [ $ret -eq 256 ]; then
|
||||||
else
|
# a former btrfs snapshot already exists
|
||||||
printf "${RED}Cancel snapshot creation${NO_COLOR}: Former snapshot with id ${GREEN}'%s'${NO_COLOR} already exists on ${BLUE}'%s'${NO_COLOR} in ${BLUE}'%s'${NO_COLOR}\n" \
|
if [ -z "$remote" ]; then
|
||||||
"$snapper_id" "$remote" "$backup_root/$snapper_snapshots"
|
printf "${RED}Cancel snapshot creation${NO_COLOR}: Former snapshot with id ${GREEN}'%s'${NO_COLOR} already exist in ${BLUE}'%s'${NO_COLOR}\n" \
|
||||||
fi
|
"$snapper_id" "$backup_root/$snapper_snapshots"
|
||||||
|
else
|
||||||
|
printf "${RED}Cancel snapshot creation${NO_COLOR}: Former snapshot with id ${GREEN}'%s'${NO_COLOR} already exists on ${BLUE}'%s'${NO_COLOR} in ${BLUE}'%s'${NO_COLOR}\n" \
|
||||||
|
"$snapper_id" "$remote" "$backup_root/$snapper_snapshots"
|
||||||
|
fi
|
||||||
|
|
||||||
# cleanup generated snapper entry
|
# cleanup generated snapper entry
|
||||||
check_snapper_failed_ids $batch
|
check_snapper_failed_ids $batch
|
||||||
die "Can't create new snapshot with given snapshot-id!"
|
die "Can't create new snapshot with given snapshot-id!"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
printf "dryrun: Would check/create path %s to store target snapshot ...\n" \
|
printf "dryrun: Would check/create path %s to store target snapshot ...\n" \
|
||||||
|
|||||||
Reference in New Issue
Block a user