6 config_file="${HOME}/.borgrepos"
9 echo "Need operation as argument, one of:"
13 echo "export_keyfiles"
23 export BORG_PASSPHRASE="${password}"
26 if [ ! -f "${config_file}" ]; then
27 echo '# file read ends at last newline' >> "${config_file}"
29 if [ "$#" -lt 1 ]; then
34 if [ "${first_arg}" = "init" ]; then
35 if [ ! "$#" -eq 1 ]; then
36 echo "Need exactly one argument: target of form user@server"
40 echo "Initializing: ${target}"
41 borg init --verbose --encryption=keyfile "${target}:${standard_repo}"
42 tmp_file="/tmp/new_borgrepos"
43 echo "${target}" > "${tmp_file}"
44 cat "${config_file}" >> "${tmp_file}"
45 cp "${tmp_file}" "${config_file}"
46 elif [ "${first_arg}" = "store" ]; then
47 if [ "$#" -lt 2 ]; then
48 echo "Need archive name and paths to archive."
55 cat "${config_file}" | while read line; do
56 first_char=$(echo "${line}" | cut -c1)
57 if [ "${first_char}" = "#" ]; then
60 repo="${line}:${standard_repo}"
61 archive="${repo}::${archive_name}"
62 echo "Creating archive: ${archive}"
63 borg create --verbose --list "${archive}" ${to_backup}
65 elif [ "${first_arg}" = "check" ]; then
66 if [ ! "$#" -eq 0 ]; then
67 echo "Need no arguments"
71 cat "${config_file}" | while read line; do
72 first_char=$(echo "${line}" | cut -c1)
73 if [ "${first_char}" = "#" ]; then
76 repo="${line}:${standard_repo}"
77 echo "Checking repo: ${repo}"
78 borg check --verbose "${repo}"
80 elif [ "${first_arg}" = "export_keyfiles" ]; then
81 if [ ! "$#" -eq 1 ]; then
82 echo "Need output tar file name."
86 tmp_dir="${HOME}/.borgtmp"
87 keyfiles_dir="${tmp_dir}/borg_keyfiles"
88 mkdir -p "${keyfiles_dir}"
89 cat "${config_file}" | while read line; do
90 first_char=$(echo "${line}" | cut -c1)
91 if [ "${first_char}" = "#" ]; then
94 repo="${line}:${standard_repo}"
95 borg key export "${repo}" "${keyfiles_dir}/${line}"
99 target=$(basename "${keyfiles_dir}")
100 tar cf "${tar_target}" "${target}"
101 mv "${tar_target}" "${cur_dir}"