config

Personal configuration.
git clone git://code.dwrz.net/config
Log | Files | Refs

backup (2512B)


      1 #!/usr/bin/env bash
      2 
      3 readonly TARGETS=(
      4   "${HOME}/.config/gnupg/"
      5   "${HOME}/.config/pass/"
      6 )
      7 
      8 readonly HOSTS=(
      9   "mobile.dwrz.net"
     10   "555.dwrz.net"
     11   "516.dwrz.net"
     12   "srv"
     13 )
     14 
     15 backup-hosts() {
     16   local target="$1"
     17 
     18   for h in "${HOSTS[@]}"; do
     19     if [[ "${h}" == "mobile.dwrz.net" ]]; then
     20       t="${target#"${HOME}"}"
     21       rsync --archive --delete --progress --verbose "${target}" \
     22 	    "${USER}@${h}":"/data/data/com.termux/files/home/${t}"
     23     else
     24       rsync --archive --delete --progress --verbose "${target}" \
     25 	    "${USER}@${h}":"${target}"
     26     fi
     27     if [[ "$?" -ne 0 ]]; then
     28       err "$0: failed rsync ${target} to ${h}"
     29     fi
     30   done
     31 }
     32 
     33 backup-b2() {
     34   local id bucket key
     35   bucket="$(pass backblaze/bucket)"
     36   id="$(pass backblaze/duplicity/keyID)"
     37   key="$(pass backblaze/duplicity/applicationKey)"
     38 
     39   # Config
     40   if ! env "B2_APPLICATION_KEY_ID"="${id}" "B2_APPLICATION_KEY"="${key}" \
     41       bbb2 sync --delete --excludeDirRegex="Signal" \
     42       "${HOME}/.config/" "b2://${bucket}/${HOSTNAME}/config";
     43   then
     44     err "$0: failed b2 'config' sync"
     45   fi
     46 
     47   # Org
     48   if ! env "B2_APPLICATION_KEY_ID"="${id}" "B2_APPLICATION_KEY"="${key}" \
     49       bbb2 sync --delete --excludeDirRegex="email" \
     50       "${HOME}/org/" "b2://${bucket}/${HOSTNAME}/org";
     51   then
     52     err "$0: failed b2 'org' sync"
     53   fi
     54 
     55   # Projects
     56   if ! env "B2_APPLICATION_KEY_ID"="${id}" "B2_APPLICATION_KEY"="${key}" \
     57        bbb2 sync --delete "${HOME}/projects/" \
     58        "b2://${bucket}/${HOSTNAME}/projects";
     59   then
     60     err "$0: failed b2 'projects' sync"
     61   fi
     62 }
     63 
     64 backup-srv() {
     65   if ! rsync --archive --delete --progress --verbose "${HOME}/archive/" \
     66        "${USER}@srv":"${HOME}/archive/";
     67   then
     68     err "$0: failed srv 'archive' sync"
     69   fi
     70   if ! rsync --archive --delete --progress --verbose "${HOME}/journal/" \
     71        "${USER}@srv":"${HOME}/journal/";
     72   then
     73     err "$0: failed srv 'journal' sync"
     74   fi
     75   if ! rsync --archive --delete --progress --verbose "${HOME}/org/" \
     76        "${USER}@srv":"${HOME}/org/";
     77   then
     78     err "$0: failed srv 'org' sync"
     79   fi
     80   if ! rsync --archive --delete --progress --verbose "${HOME}/projects/" \
     81        "${USER}@srv":"${HOME}/projects/";
     82   then
     83     err "$0: failed srv 'projects' sync"
     84   fi
     85 }
     86 
     87 main() {
     88   # Backup targets.
     89   for target in "${TARGETS[@]}"; do
     90     if [[ ! -e "${target}" ]]; then
     91       err "$0: failed to backup ${target}: not found"
     92       continue
     93     fi
     94 
     95     backup-hosts "${target}"
     96   done
     97 
     98   # Backup srv.
     99   backup-srv
    100 
    101   # Backup B2.
    102   backup-b2
    103 }
    104 
    105 main "$@"