5 config_file="${HOME}/.borgrepos"
8 echo "Need operation as argument, one of:"
12 echo "export_keyfiles"
22 export BORG_PASSPHRASE="${password}"
25 if [ ! -f "${config_file}" ]; then
26 echo '# file read ends at last newline' >> "${config_file}"
28 if [ "$#" -lt 1 ]; then
33 if [ "${first_arg}" = "init" ]; then
34 if [ ! "$#" -eq 1 ]; then
35 echo "Need exactly one argument: target of form user@server"
39 echo "Initializing: ${target}"
40 borg init --verbose --encryption=keyfile "${target}:${standard_repo}"
41 tmp_file="/tmp/new_borgrepos"
42 echo "${target}" > "${tmp_file}"
43 cat "${config_file}" >> "${tmp_file}"
44 cp "${tmp_file}" "${config_file}"
45 elif [ "${first_arg}" = "store" ]; then
46 if [ ! "$#" -eq 2 ]; then
47 echo "Need precisely two arguments: archive name and path to archive."
54 cat "${config_file}" | while read line; do
55 first_char=$(echo "${line}" | cut -c1)
56 if [ "${first_char}" = "#" ]; then
59 repo="${line}:${standard_repo}"
60 archive="${repo}::${archive_name}-{utcnow:%Y-%m-%dT%H:%M}"
61 echo "Creating archive: ${archive}"
62 borg create --verbose --list "${archive}" "${to_backup}"
64 elif [ "${first_arg}" = "check" ]; then
65 if [ ! "$#" -eq 0 ]; then
66 echo "Need no arguments"
70 cat "${config_file}" | while read line; do
71 first_char=$(echo "${line}" | cut -c1)
72 if [ "${first_char}" = "#" ]; then
75 repo="${line}:${standard_repo}"
76 echo "Checking repo: ${repo}"
77 borg check --verbose "${repo}"
79 elif [ "${first_arg}" = "export_keyfiles" ]; then
80 if [ ! "$#" -eq 1 ]; then
81 echo "Need output tar file name."
85 tmp_dir="${HOME}/.borgtmp"
86 keyfiles_dir="${tmp_dir}/borg_keyfiles"
87 mkdir -p "${keyfiles_dir}"
88 cat "${config_file}" | while read line; do
89 first_char=$(echo "${line}" | cut -c1)
90 if [ "${first_char}" = "#" ]; then
93 repo="${line}:${standard_repo}"
94 borg key export "${repo}" "${keyfiles_dir}/${line}"
98 target=$(basename "${keyfiles_dir}")
99 tar cf "${tar_target}" "${target}"
100 mv "${tar_target}" "${cur_dir}"