5 config_file="${HOME}/.borgrepos"
8 echo "Need operation as argument, one of:"
12 echo "export_keyfiles"
23 printf "Borg passphrase: "
27 export BORG_PASSPHRASE="${password}"
30 if [ ! -f "${config_file}" ]; then
31 echo '# file read ends at last newline' >> "${config_file}"
33 if [ "$#" -lt 1 ]; then
38 if [ "${first_arg}" = "init" ]; then
39 if [ ! "$#" -eq 1 ]; then
40 echo "Need exactly one argument: target of form user@server"
44 echo "Initializing: ${target}"
45 borg init --verbose --encryption=keyfile "${target}:${standard_repo}"
46 tmp_file="/tmp/new_borgrepos"
47 echo "${target}" > "${tmp_file}"
48 cat "${config_file}" >> "${tmp_file}"
49 cp "${tmp_file}" "${config_file}"
50 elif [ "${first_arg}" = "store" ]; then
51 if [ ! "$#" -eq 2 ]; then
52 echo "Need precisely two arguments: archive name and path to archive."
59 cat "${config_file}" | while read line; do
60 first_char=$(echo "${line}" | cut -c1)
61 if [ "${first_char}" = "#" ]; then
64 repo="${line}:${standard_repo}"
65 archive="${repo}::${archive_name}-{utcnow:%Y-%m-%dT%H:%M}"
66 echo "Creating archive: ${archive}"
67 borg create --verbose --list "${archive}" "${to_backup}"
69 elif [ "${first_arg}" = "check" ]; then
70 if [ ! "$#" -eq 0 ]; then
71 echo "Need no arguments"
75 cat "${config_file}" | while read line; do
76 first_char=$(echo "${line}" | cut -c1)
77 if [ "${first_char}" = "#" ]; then
80 repo="${line}:${standard_repo}"
81 echo "Checking repo: ${repo}"
82 borg check --verbose "${repo}"
84 elif [ "${first_arg}" = "export_keyfiles" ]; then
85 if [ ! "$#" -eq 1 ]; then
86 echo "Need output tar file name."
90 tmp_dir="${HOME}/.borgtmp"
91 keyfiles_dir="${tmp_dir}/borg_keyfiles"
92 mkdir -p "${keyfiles_dir}"
93 cat "${config_file}" | while read line; do
94 first_char=$(echo "${line}" | cut -c1)
95 if [ "${first_char}" = "#" ]; then
98 repo="${line}:${standard_repo}"
99 borg key export "${repo}" "${keyfiles_dir}/${line}"
103 target=$(basename "${keyfiles_dir}")
104 tar cf "${tar_target}" "${target}"
105 mv "${tar_target}" "${cur_dir}"
108 elif [ "${first_arg}" = "orgpush" ]; then
109 archive_name="orgdir"
112 cat "${config_file}" | while read line; do
113 first_char=$(echo "${line}" | cut -c1)
114 if [ "${first_char}" = "#" ]; then
117 repo="${line}:${standard_repo}"
118 archive="${repo}::${archive_name}-{utcnow:%Y-%m-%dT%H:%M}"
119 echo "Creating archive: ${archive}"
120 borg create --verbose --list "${archive}" "${to_backup}" --exclude ~/org/.git
122 elif [ "${first_arg}" = "orgpull" ]; then
123 archive_name="orgdir"
126 cat "${config_file}" | while read line; do
127 first_char=$(echo "${line}" | cut -c1)
128 if [ "${first_char}" = "#" ]; then
131 repo="${line}:${standard_repo}"
132 archive=$(borg list "${repo}" | grep "${orgdir}" | tail -1 | cut -f1 -d' ')
133 echo "Pulling archive: ${archive}"
134 borg extract --verbose "${repo}::${archive}"