5 config_file="${HOME}/.borgrepos"
8 echo "Need operation as argument, one of:"
12 echo "export_keyfiles"
19 if [ "${#SSH_AGENT_PID}" -eq 0 ]; then
24 if [ "${#BORG_PASSPHRASE}" -eq 0 ]; then
26 printf "Borg passphrase: "
30 export BORG_PASSPHRASE="${password}"
34 if [ ! -f "${config_file}" ]; then
35 echo '# file read ends at last newline' >> "${config_file}"
37 if [ "$#" -lt 1 ]; then
42 if [ "${first_arg}" = "init" ]; then
43 if [ ! "$#" -eq 1 ]; then
44 echo "Need exactly one argument: target of form user@server"
48 echo "Initializing: ${target}"
49 borg init --verbose --encryption=keyfile "${target}:${standard_repo}"
50 tmp_file="/tmp/new_borgrepos"
51 echo "${target}" > "${tmp_file}"
52 cat "${config_file}" >> "${tmp_file}"
53 cp "${tmp_file}" "${config_file}"
54 elif [ "${first_arg}" = "store" ]; then
55 if [ ! "$#" -eq 2 ]; then
56 echo "Need precisely two arguments: archive name and path to archive."
63 cat "${config_file}" | while read line; do
64 first_char=$(echo "${line}" | cut -c1)
65 if [ "${first_char}" = "#" ]; then
68 repo="${line}:${standard_repo}"
69 archive="${repo}::${archive_name}-{utcnow:%Y-%m-%dT%H:%M}"
70 echo "Creating archive: ${archive}"
71 borg create --verbose --list "${archive}" "${to_backup}"
73 elif [ "${first_arg}" = "check" ]; then
74 if [ ! "$#" -eq 0 ]; then
75 echo "Need no arguments"
79 cat "${config_file}" | while read line; do
80 first_char=$(echo "${line}" | cut -c1)
81 if [ "${first_char}" = "#" ]; then
84 repo="${line}:${standard_repo}"
85 echo "Checking repo: ${repo}"
86 borg check --verbose "${repo}"
88 elif [ "${first_arg}" = "export_keyfiles" ]; then
89 if [ ! "$#" -eq 1 ]; then
90 echo "Need output tar file name."
94 tmp_dir="${HOME}/.borgtmp"
95 keyfiles_dir="${tmp_dir}/borg_keyfiles"
96 mkdir -p "${keyfiles_dir}"
97 cat "${config_file}" | while read line; do
98 first_char=$(echo "${line}" | cut -c1)
99 if [ "${first_char}" = "#" ]; then
102 repo="${line}:${standard_repo}"
103 borg key export "${repo}" "${keyfiles_dir}/${line}"
107 target=$(basename "${keyfiles_dir}")
108 tar cf "${tar_target}" "${target}"
109 mv "${tar_target}" "${cur_dir}"
112 elif [ "${first_arg}" = "orgpush" ]; then
113 archive_name="orgdir"
116 cat "${config_file}" | while read line; do
117 first_char=$(echo "${line}" | cut -c1)
118 if [ "${first_char}" = "#" ]; then
121 repo="${line}:${standard_repo}"
122 archive="${repo}::${archive_name}-{utcnow:%Y-%m-%dT%H:%M}"
123 echo "Creating archive: ${archive}"
124 borg create --verbose --list "${archive}" "${to_backup}" --exclude ~/org/.git
126 elif [ "${first_arg}" = "orgpull" ]; then
127 archive_name="orgdir"
130 cat "${config_file}" | while read line; do
131 first_char=$(echo "${line}" | cut -c1)
132 if [ "${first_char}" = "#" ]; then
135 repo="${line}:${standard_repo}"
136 archive=$(borg list "${repo}" | grep "${orgdir}" | tail -1 | cut -f1 -d' ')
137 echo "Pulling archive: ${archive}"
138 borg extract --verbose "${repo}::${archive}"