X-Git-Url: https://plomlompom.com/repos/?a=blobdiff_plain;f=all_new_2018%2Fborg.sh;h=ec18029aec81f18bd85fccfd916fa37e84ab25a4;hb=722d0def8e15b2f96ef5190e09135f6cb2c1b09d;hp=759779564452f9b80a82ba9df9cfbe72ed16a586;hpb=15b7039e8d5811a8c309a428d30999283715b0eb;p=config diff --git a/all_new_2018/borg.sh b/all_new_2018/borg.sh index 7597795..ec18029 100755 --- a/all_new_2018/borg.sh +++ b/all_new_2018/borg.sh @@ -1,6 +1,5 @@ #!/bin/sh set -e -set -x standard_repo="borg" config_file="${HOME}/.borgrepos" @@ -11,10 +10,14 @@ usage() { echo "store" echo "check" echo "export_keyfiles" + echo "orgpush" + echo "orgpull" false } read_pw() { + eval $(ssh-agent) + ssh-add stty -echo printf "Passphrase: " read password @@ -44,8 +47,8 @@ if [ "${first_arg}" = "init" ]; then cat "${config_file}" >> "${tmp_file}" cp "${tmp_file}" "${config_file}" elif [ "${first_arg}" = "store" ]; then - if [ "$#" -lt 2 ]; then - echo "Need archive name and paths to archive." + if [ ! "$#" -eq 2 ]; then + echo "Need precisely two arguments: archive name and path to archive." false fi archive_name=$1 @@ -58,9 +61,9 @@ elif [ "${first_arg}" = "store" ]; then continue fi repo="${line}:${standard_repo}" - archive="${repo}::${archive_name}" + archive="${repo}::${archive_name}-{utcnow:%Y-%m-%dT%H:%M}" echo "Creating archive: ${archive}" - borg create --verbose --list "${archive}" ${to_backup} + borg create --verbose --list "${archive}" "${to_backup}" done elif [ "${first_arg}" = "check" ]; then if [ ! "$#" -eq 0 ]; then @@ -101,6 +104,35 @@ elif [ "${first_arg}" = "export_keyfiles" ]; then mv "${tar_target}" "${cur_dir}" cd rm -rf "${tmp_dir}" +elif [ "${first_arg}" = "orgpush" ]; then + archive_name="orgdir" + to_backup=~/org + read_pw + cat "${config_file}" | while read line; do + first_char=$(echo "${line}" | cut -c1) + if [ "${first_char}" = "#" ]; then + continue + fi + repo="${line}:${standard_repo}" + archive="${repo}::${archive_name}-{utcnow:%Y-%m-%dT%H:%M}" + echo "Creating archive: ${archive}" + borg create --verbose --list "${archive}" "${to_backup}" --exclude ~/org/.git + done +elif [ "${first_arg}" = "orgpull" ]; then + archive_name="orgdir" + read_pw + cd / + cat "${config_file}" | while read line; do + first_char=$(echo "${line}" | cut -c1) + if [ "${first_char}" = "#" ]; then + continue + fi + repo="${line}:${standard_repo}" + archive=$(borg list "${repo}" | grep "${orgdir}" | tail -1 | cut -f1 -d' ') + echo "Pulling archive: ${archive}" + borg extract --verbose "${repo}::${archive}" + break + done else usage fi