Revert "logging goes to journal automatically from systemd service"

This reverts commit 153b43b1b7.
This commit is contained in:
James Barnett
2017-01-30 20:15:21 -06:00
parent 7cb1ca9b46
commit e7085c4f92

View File

@@ -82,6 +82,12 @@ fi
# It's important not to change this userdata in the snapshots, since that's how # It's important not to change this userdata in the snapshots, since that's how
# we find the previous one. # we find the previous one.
TMPDIR=$(mktemp -d)
PIPE=$TMPDIR/snap-sync.out
mkfifo $PIPE
systemd-cat -t "snap-sync" < $PIPE &
exec 3>$PIPE
TARGETS="$(findmnt -n -v -t btrfs -o TARGET --list)" TARGETS="$(findmnt -n -v -t btrfs -o TARGET --list)"
UUIDS="$(findmnt -n -v -t btrfs -o UUID --list)" UUIDS="$(findmnt -n -v -t btrfs -o UUID --list)"
@@ -136,13 +142,13 @@ fi
selected_uuid="${UUIDS_ARRAY[$((disk))]}" selected_uuid="${UUIDS_ARRAY[$((disk))]}"
selected_mnt="${TARGETS_ARRAY[$((disk))]}" selected_mnt="${TARGETS_ARRAY[$((disk))]}"
printf "\nYou selected the disk with UUID %s.\n" "$selected_uuid" printf "\nYou selected the disk with UUID %s.\n" "$selected_uuid" | tee $PIPE
printf "The disk is mounted at %s.\n" "$selected_mnt" printf "The disk is mounted at %s.\n" "$selected_mnt" | tee $PIPE
if [[ -f /etc/conf.d/snapper ]]; then if [[ -f /etc/conf.d/snapper ]]; then
source /etc/conf.d/snapper source /etc/conf.d/snapper
else else
printf "ERROR: /etc/conf.d/snapper does not exist!\n" printf "ERROR: /etc/conf.d/snapper does not exist!\n" | tee $PIPE
error_exit error_exit
fi fi
@@ -177,7 +183,7 @@ for x in $selected_configs; do
mybackupdir=$(snapper -c root list -t single | awk -F"|" '/'"$selected_uuid"'/ {print $5}' | awk -F "," '/backupdir/ {print $1}' | awk -F"=" '{print $2}') mybackupdir=$(snapper -c root list -t single | awk -F"|" '/'"$selected_uuid"'/ {print $5}' | awk -F "," '/backupdir/ {print $1}' | awk -F"=" '{print $2}')
BACKUPDIR="$selected_mnt/$mybackupdir" BACKUPDIR="$selected_mnt/$mybackupdir"
if [[ ! -d $BACKUPDIR ]]; then if [[ ! -d $BACKUPDIR ]]; then
printf "ERROR: %s is not a directory on %s.\n" "$BACKUPDIR" "$selected_uuid" printf "ERROR: %s is not a directory on %s.\n" "$BACKUPDIR" "$selected_uuid" | tee $PIPE
error_exit error_exit
fi fi
fi fi
@@ -189,7 +195,7 @@ done
for x in $selected_configs; do for x in $selected_configs; do
if [[ "$(sudo snapper -c root list -t single | awk '/snap-sync backup in progress/ {cnt++} END {print cnt}')" -gt 0 ]]; then if [[ "$(sudo snapper -c root list -t single | awk '/snap-sync backup in progress/ {cnt++} END {print cnt}')" -gt 0 ]]; then
printf "Note: Previous failed snap-sync backup snapshots found for '$x'.\n" printf "Note: Previous failed snap-sync backup snapshots found for '$x'.\n" | tee $PIPE
fi fi
SNAP_SYNC_EXCLUDE=no SNAP_SYNC_EXCLUDE=no
@@ -212,13 +218,13 @@ for x in $selected_configs; do
BACKUPDIR="${BACKUPDIRS_ARRAY[$x]}" BACKUPDIR="${BACKUPDIRS_ARRAY[$x]}"
printf "Creating new snapshot for $x...\n" printf "Creating new snapshot for $x...\n" | tee $PIPE
new_number=$(snapper -c "$x" create --print-number -d "snap-sync backup in progress") new_number=$(snapper -c "$x" create --print-number -d "snap-sync backup in progress")
new_snapshot=$SUBVOLUME/.snapshots/$new_number/snapshot new_snapshot=$SUBVOLUME/.snapshots/$new_number/snapshot
new_info=$SUBVOLUME/.snapshots/$new_number/info.xml new_info=$SUBVOLUME/.snapshots/$new_number/info.xml
sync sync
backup_location=$BACKUPDIR/$x/$new_number/ backup_location=$BACKUPDIR/$x/$new_number/
printf "Will backup %s to %s\n" "$new_snapshot" "$backup_location/snapshot" printf "Will backup %s to %s\n" "$new_snapshot" "$backup_location/snapshot" | tee $PIPE
cont_backup="" cont_backup=""
if [[ $noconfirm == "yes" ]]; then if [[ $noconfirm == "yes" ]]; then
@@ -243,18 +249,18 @@ for x in $selected_configs; do
if [[ -z "$old_num" ]]; then if [[ -z "$old_num" ]]; then
printf "Sending first snapshot for %s...\n" "$x" printf "Sending first snapshot for %s...\n" "$x" | tee $PIPE
btrfs send "$new_snapshot" | btrfs receive "$backup_location" &>/dev/null btrfs send "$new_snapshot" | btrfs receive "$backup_location" &>/dev/null
else else
printf "Sending incremental snapshot for %s...\n" "$x" printf "Sending incremental snapshot for %s...\n" "$x" | tee $PIPE
# Sends the difference between the new snapshot and old snapshot to the # Sends the difference between the new snapshot and old snapshot to the
# backup location. Using the -c flag instead of -p tells it that there # backup location. Using the -c flag instead of -p tells it that there
# is an identical subvolume to the old snapshot at the receiving # is an identical subvolume to the old snapshot at the receiving
# location where it can get its data. This helps speed up the transfer. # location where it can get its data. This helps speed up the transfer.
btrfs send "$new_snapshot" -c "$old_snap" | btrfs receive "$backup_location" &>/dev/null btrfs send "$new_snapshot" -c "$old_snap" | btrfs receive "$backup_location" &>/dev/null
printf "Deleting old snapshot for $x...\n" printf "Deleting old snapshot for $x...\n" | tee $PIPE
snapper -c "$x" delete "$old_num" snapper -c "$x" delete "$old_num"
fi fi
@@ -263,14 +269,14 @@ for x in $selected_configs; do
userdata="backupdir=$mybackupdir, uuid=$selected_uuid" userdata="backupdir=$mybackupdir, uuid=$selected_uuid"
# Tag new snapshot as the latest # Tag new snapshot as the latest
printf "Tagging new snapshot as latest backup for $x...\n" printf "Tagging new snapshot as latest backup for $x...\n" | tee $PIPE
snapper -v -c "$x" modify -d "$description" -u "$userdata" "$new_number" snapper -v -c "$x" modify -d "$description" -u "$userdata" "$new_number"
printf "Backup complete for configuration %s.\n" "$x" printf "Backup complete for configuration %s.\n" "$x" > $PIPE
done done
printf "\nDone!\n" printf "\nDone!\n" | tee $PIPE
exec 3>&- exec 3>&-
for u in $(users); do for u in $(users); do