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
26 if [ "${#BORG_PASSPHRASE}" -eq 0 ]; then
28 printf "Borg passphrase: "
32 export BORG_PASSPHRASE="${password}"
36 if [ ! -f "${config_file}" ]; then
37 echo '# file read ends at last newline' >> "${config_file}"
39 if [ "$#" -lt 1 ]; then
44 if [ "${first_arg}" = "init" ]; then
45 if [ ! "$#" -eq 1 ]; then
46 echo "Need exactly one argument: target of form user@server"
50 echo "Initializing: ${target}"
51 borg init --verbose --encryption=keyfile "${target}:${standard_repo}"
52 tmp_file="/tmp/new_borgrepos"
53 echo "${target}" > "${tmp_file}"
54 cat "${config_file}" >> "${tmp_file}"
55 cp "${tmp_file}" "${config_file}"
56 elif [ "${first_arg}" = "store" ]; then
57 if [ ! "$#" -eq 2 ]; then
58 echo "Need precisely two arguments: archive name and path to archive."
65 cat "${config_file}" | while read line; do
66 first_char=$(echo "${line}" | cut -c1)
67 if [ "${first_char}" = "#" ]; then
70 repo="${line}:${standard_repo}"
71 archive="${repo}::${archive_name}-{utcnow:%Y-%m-%dT%H:%M}"
72 echo "Creating archive: ${archive}"
73 borg create --verbose --list "${archive}" "${to_backup}"
75 elif [ "${first_arg}" = "check" ]; then
76 if [ ! "$#" -eq 0 ]; then
77 echo "Need no arguments"
81 cat "${config_file}" | while read line; do
82 first_char=$(echo "${line}" | cut -c1)
83 if [ "${first_char}" = "#" ]; then
86 repo="${line}:${standard_repo}"
87 echo "Checking repo: ${repo}"
88 borg check --verbose "${repo}"
90 elif [ "${first_arg}" = "export_keyfiles" ]; then
91 if [ ! "$#" -eq 1 ]; then
92 echo "Need output tar file name."
96 tmp_dir="${HOME}/.borgtmp"
97 keyfiles_dir="${tmp_dir}/borg_keyfiles"
98 mkdir -p "${keyfiles_dir}"
99 cat "${config_file}" | while read line; do
100 first_char=$(echo "${line}" | cut -c1)
101 if [ "${first_char}" = "#" ]; then
104 repo="${line}:${standard_repo}"
105 borg key export "${repo}" "${keyfiles_dir}/${line}"
109 target=$(basename "${keyfiles_dir}")
110 tar cf "${tar_target}" "${target}"
111 mv "${tar_target}" "${cur_dir}"
114 elif [ "${first_arg}" = "orgpush" ]; then
115 archive_name="orgdir"
118 cat "${config_file}" | while read line; do
119 first_char=$(echo "${line}" | cut -c1)
120 if [ "${first_char}" = "#" ]; then
123 repo="${line}:${standard_repo}"
124 archive="${repo}::${archive_name}-{utcnow:%Y-%m-%dT%H:%M}"
125 echo "Creating archive: ${archive}"
126 borg create --verbose --list "${archive}" "${to_backup}" --exclude ~/org/.git
128 elif [ "${first_arg}" = "orgpull" ]; then
129 echo "Doing ORGPULL, potentially overwriting important data. Hit Return to continue, last chance to abort!"
131 archive_name="orgdir"
134 cat "${config_file}" | while read line; do
135 first_char=$(echo "${line}" | cut -c1)
136 if [ "${first_char}" = "#" ]; then
139 repo="${line}:${standard_repo}"
140 archive=$(borg list "${repo}" | grep "${orgdir}" | tail -1 | cut -f1 -d' ')
141 echo "Pulling archive: ${archive}"
142 borg extract --verbose "${repo}::${archive}"