sync/shell/.zsh/borg.zsh

122 lines
3.5 KiB
Bash
Raw Normal View History

2016-08-29 11:54:43 -04:00
b-list() {
if [[ -z "$1" ]]; then
2018-11-04 12:23:59 -05:00
column -t <(borg list "::")
2016-08-29 11:54:43 -04:00
else
2018-11-04 12:23:59 -05:00
borg list "::$1"
2016-08-29 11:54:43 -04:00
fi
}
b-delete() {
2016-09-27 13:48:54 -04:00
while (( $# > 0 )); do
if [[ ! -z "$1" ]]; then
echo "Deleting... $1"
2018-11-04 12:23:59 -05:00
borg delete "::$1"
2016-09-27 13:48:54 -04:00
fi
shift
done
2016-08-29 11:54:43 -04:00
}
b-create() {
2016-09-09 12:01:04 -04:00
local SUDO=""
if command -v sudo > /dev/null; then
SUDO="$(command -v sudo)"
2016-08-29 11:54:43 -04:00
fi
2017-11-28 16:21:03 -05:00
local IGNORE_FILE="/tmp/$(uuidgen)"
cat /home/stonewareslord/syncthing/me/backup{,/"$(hostname)"}/nobackup > "$IGNORE_FILE"
if [[ -f "/home/stonewareslord/syncthing/me/backup/$(hostname)/mount" ]]; then
"$SUDO" "/home/stonewareslord/syncthing/me/backup/$(hostname)/mount"
fi
2018-11-04 12:23:59 -05:00
"$SUDO" borg create -vpsx --exclude-caches --compression lzma,7 --exclude-from "$IGNORE_FILE" "::$(hostname)-$(uuidgen)" / /boot /home
2016-08-29 11:54:43 -04:00
}
b-rename() {
2018-11-04 12:23:59 -05:00
borg rename -v "::$1" "$2"
}
b-info() {
2018-11-04 12:23:59 -05:00
borg info "::$1"
}
2016-09-23 00:29:41 -04:00
b-diff() {
2018-11-04 12:23:59 -05:00
borg list "::"
2016-09-23 00:29:41 -04:00
echo -n "First ID: "
read ID1
echo -n "Second ID: "
read ID2
if [ -z "$ID2" ] || [ -z "$ID2" ]; then
echo "No id" >&2
return 1
fi
BASEPATH="/tmp/$(uuidgen)"
mkdir -p "$BASEPATH"
FILE_LIST1="$BASEPATH/$(uuidgen)"
FILE_LIST2="$BASEPATH/$(uuidgen)"
A_DIFFS="$BASEPATH/$(uuidgen)"
B_DIFFS="$BASEPATH/$(uuidgen)"
FILE_SIZE_LIST1="$BASEPATH/$(uuidgen)"
FILE_SIZE_LIST2="$BASEPATH/$(uuidgen)"
COMPLETED_FILE1="$BASEPATH/$(uuidgen)"
COMPLETED_FILE2="$BASEPATH/$(uuidgen)"
echo "FILE_LIST1: $FILE_LIST1"
echo "FILE_LIST2: $FILE_LIST2"
echo "A_DIFS: $A_DIFFS"
echo "B_DIFFS: $B_DIFFS"
echo "FILE_SIZE_LIST1: $FILE_SIZE_LIST1"
echo "FILE_SIZE_LIST2: $FILE_SIZE_LIST2"
echo "COMPLETED_FILE1: $COMPLETED_FILE1"
echo "COMPLETED_FILE2: $COMPLETED_FILE2"
2018-11-04 12:23:59 -05:00
borg list --short "::$ID1" | pv -N "Getting List 1" > "$FILE_LIST1"
borg list --short "::$ID2" | pv -N "Getting List 2" > "$FILE_LIST2"
2016-09-23 00:29:41 -04:00
# Find differences and calculate them
diff <(pv -cN "List 1 Diff" "$FILE_LIST1") <(pv -cN "List 1 Diff" "$FILE_LIST2") > >(ag '^<' | perl -pe 's/^< //' > "$A_DIFFS") > >(ag '^>' | perl -pe 's/^> //' > "$B_DIFFS")
# Truncate everything
:|tee "$FILE_LIST1" "$FILE_LIST2"
# Calculate sizes of file1
while read i
do
test -f /"$i" && du -sh /"$i" 2>/dev/null >> "$FILE_SIZE_LIST1"
done < <(pv -N "Calculating a sizes" "$A_DIFFS")
# Sort everything
pv -N "Sorting a sizes" "$FILE_SIZE_LIST1" | sort -h | tac > "$COMPLETED_FILE1"
# Calculate sizes of file2
while read i
do
test -f /"$i" && du -sh /"$i" 2>/dev/null >> "$FILE_SIZE_LIST2"
done < <(pv -N "Calculating b sizes" "$B_DIFFS")
# Sort everything
pv -N "Sorting b sizes" "$FILE_SIZE_LIST2" | sort -h | tac > "$COMPLETED_FILE2"
# Truncate everything
:|tee "$A_DIFFS" "$B_DIFFS" "$FILE_SIZE_LIST1" "$FILE_SIZE_LIST2"
echo "In first backup:"
echo "$COMPLETED_FILE1"
echo "In second backup:"
echo "$COMPLETED_FILE2"
}
b-size() {
2018-11-04 12:23:59 -05:00
borg list "::"
2016-09-23 00:29:41 -04:00
echo -n "ID: "
read ID
if [ -z "$ID" ]; then
echo "No id" >&2
return 1
fi
FILE_LIST="/tmp/$(uuidgen)"
FILE_SIZE_LIST="/tmp/$(uuidgen)"
COMPLETED_FILE="/tmp/$(uuidgen)"
echo "FILE_LIST: $FILE_LIST"
echo "FILE_SIZE_LIST: $FILE_SIZE_LIST"
echo "COMPLETED_FILE: $COMPLETED_FILE"
2018-11-04 12:23:59 -05:00
borg list --short "::$ID" | pv -N "Getting List" > "$FILE_LIST"
2016-09-23 00:29:41 -04:00
while read i
do
test -f /"$i" && du -sh /"$i" 2>/dev/null >> "$FILE_SIZE_LIST"
done < <(pv -N "Calculating Sizes" "$FILE_LIST")
:>"$FILE_LIST"
pv -N "Sorting List" "$FILE_SIZE_LIST" | sort -h | tac > "$COMPLETED_FILE"
:>"$FILE_SIZE_LIST"
less "$COMPLETED_FILE"
}
2016-10-06 13:16:35 -04:00
b-extract() {
local BACKUP="$1"
shift
2018-11-04 12:23:59 -05:00
borg extract "::$BACKUP" $*
2016-10-06 13:16:35 -04:00
}
b-cmd() {
2018-11-04 12:23:59 -05:00
echo "::" $*
}