5 config_file="${HOME}/.borgrepos"
8 echo "Need operation as argument, one of:"
12 echo "export_keyfiles"
24 export BORG_PASSPHRASE="${password}"
27 if [ ! -f "${config_file}" ]; then
28 echo '# file read ends at last newline' >> "${config_file}"
30 if [ "$#" -lt 1 ]; then
35 if [ "${first_arg}" = "init" ]; then
36 if [ ! "$#" -eq 1 ]; then
37 echo "Need exactly one argument: target of form user@server"
41 echo "Initializing: ${target}"
42 borg init --verbose --encryption=keyfile "${target}:${standard_repo}"
43 tmp_file="/tmp/new_borgrepos"
44 echo "${target}" > "${tmp_file}"
45 cat "${config_file}" >> "${tmp_file}"
46 cp "${tmp_file}" "${config_file}"
47 elif [ "${first_arg}" = "store" ]; then
48 if [ ! "$#" -eq 2 ]; then
49 echo "Need precisely two arguments: archive name and path to archive."
56 cat "${config_file}" | while read line; do
57 first_char=$(echo "${line}" | cut -c1)
58 if [ "${first_char}" = "#" ]; then
61 repo="${line}:${standard_repo}"
62 archive="${repo}::${archive_name}-{utcnow:%Y-%m-%dT%H:%M}"
63 echo "Creating archive: ${archive}"
64 borg create --verbose --list "${archive}" "${to_backup}"
66 elif [ "${first_arg}" = "check" ]; then
67 if [ ! "$#" -eq 0 ]; then
68 echo "Need no arguments"
72 cat "${config_file}" | while read line; do
73 first_char=$(echo "${line}" | cut -c1)
74 if [ "${first_char}" = "#" ]; then
77 repo="${line}:${standard_repo}"
78 echo "Checking repo: ${repo}"
79 borg check --verbose "${repo}"
81 elif [ "${first_arg}" = "export_keyfiles" ]; then
82 if [ ! "$#" -eq 1 ]; then
83 echo "Need output tar file name."
87 tmp_dir="${HOME}/.borgtmp"
88 keyfiles_dir="${tmp_dir}/borg_keyfiles"
89 mkdir -p "${keyfiles_dir}"
90 cat "${config_file}" | while read line; do
91 first_char=$(echo "${line}" | cut -c1)
92 if [ "${first_char}" = "#" ]; then
95 repo="${line}:${standard_repo}"
96 borg key export "${repo}" "${keyfiles_dir}/${line}"
100 target=$(basename "${keyfiles_dir}")
101 tar cf "${tar_target}" "${target}"
102 mv "${tar_target}" "${cur_dir}"