From cbc4dd1f7a34ba23f4398708f0ad3bd35f0bf06f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yaroslav=20de=20la=20Pe=C3=B1a=20Smirnov?= Date: Tue, 16 Feb 2021 23:20:18 +0300 Subject: New script: bkup Shortcut script to rsync frequently rsync'ed source dirs to frequent targets. --- dotfiles/.local/bin/bkup | 52 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100755 dotfiles/.local/bin/bkup (limited to 'dotfiles/.local') diff --git a/dotfiles/.local/bin/bkup b/dotfiles/.local/bin/bkup new file mode 100755 index 0000000..0e4d503 --- /dev/null +++ b/dotfiles/.local/bin/bkup @@ -0,0 +1,52 @@ +#!/bin/sh + +# Yaroslav de la Peña Smirnov 2021 +# Shortcut script for backing up files with rsync. +# By default it starts a dry run, to check that there are no conflicts. To +# commit the copy, i.e. do a normal (non-dry) run, use -c as the first or last +# argument. + +############################# Config example ################################### +## Lines in the locations file contain the shortcuts for the sources and +## destinations. For example, sources: +# src d /home/yaroslav/docs +# src m /home/yaroslav/music +## destinations: +# dst rm yaroslav@example.com: +# dst hd /mnt/disk/ +## The columns MUST be separated by ONE tab character +################################################################################ + +locations="$HOME/docs/data/bkup/locations" +ops="-ahv --delete --progress" + +if [ "$1" = "-c" ]; then + srckey="$2" + dstkey="$3" +else + if [ "$3" != "-c" ]; then + ops="-ahvn --delete" + fi + srckey="$1" + dstkey="$2" +fi + +if [ -z $srckey ] || [ -z $dstkey ]; then + echo "Usage: bkup [-c] [-c]" + exit 1 +fi + +relsrc="$(grep -E "src[[:space:]]+$srckey" "$locations" | cut -f3)" +if [ -z "$relsrc" ]; then + echo "Source shortcut not found" + exit 1 +fi +target="$(echo "$relsrc" | awk -F'/' '{print $(NF)}')" + +reldst="$(grep -E "dst[[:space:]]+$dstkey[[:space:]]+" "$locations" | cut -f3)" +if [ -z "$reldst" ]; then + echo "Destination shortcut not found" + exit 1 +fi + +rsync $ops "$relsrc/" "$reldst$target/" -- cgit v1.2.3