5 config_file="${HOME}/.borgrepos"
8 echo "Need operation as argument, one of:"
12 echo "export_keyfiles"
26 export BORG_PASSPHRASE="${password}"
29 if [ ! -f "${config_file}" ]; then
30 echo '# file read ends at last newline' >> "${config_file}"
32 if [ "$#" -lt 1 ]; then
37 if [ "${first_arg}" = "init" ]; then
38 if [ ! "$#" -eq 1 ]; then
39 echo "Need exactly one argument: target of form user@server"
43 echo "Initializing: ${target}"
44 borg init --verbose --encryption=keyfile "${target}:${standard_repo}"
45 tmp_file="/tmp/new_borgrepos"
46 echo "${target}" > "${tmp_file}"
47 cat "${config_file}" >> "${tmp_file}"
48 cp "${tmp_file}" "${config_file}"
49 elif [ "${first_arg}" = "store" ]; then
50 if [ ! "$#" -eq 2 ]; then
51 echo "Need precisely two arguments: archive name and path to archive."
58 cat "${config_file}" | while read line; do
59 first_char=$(echo "${line}" | cut -c1)
60 if [ "${first_char}" = "#" ]; then
63 repo="${line}:${standard_repo}"
64 archive="${repo}::${archive_name}-{utcnow:%Y-%m-%dT%H:%M}"
65 echo "Creating archive: ${archive}"
66 borg create --verbose --list "${archive}" "${to_backup}"
68 elif [ "${first_arg}" = "check" ]; then
69 if [ ! "$#" -eq 0 ]; then
70 echo "Need no arguments"
74 cat "${config_file}" | while read line; do
75 first_char=$(echo "${line}" | cut -c1)
76 if [ "${first_char}" = "#" ]; then
79 repo="${line}:${standard_repo}"
80 echo "Checking repo: ${repo}"
81 borg check --verbose "${repo}"
83 elif [ "${first_arg}" = "export_keyfiles" ]; then
84 if [ ! "$#" -eq 1 ]; then
85 echo "Need output tar file name."
89 tmp_dir="${HOME}/.borgtmp"
90 keyfiles_dir="${tmp_dir}/borg_keyfiles"
91 mkdir -p "${keyfiles_dir}"
92 cat "${config_file}" | while read line; do
93 first_char=$(echo "${line}" | cut -c1)
94 if [ "${first_char}" = "#" ]; then
97 repo="${line}:${standard_repo}"
98 borg key export "${repo}" "${keyfiles_dir}/${line}"
102 target=$(basename "${keyfiles_dir}")
103 tar cf "${tar_target}" "${target}"
104 mv "${tar_target}" "${cur_dir}"
107 elif [ "${first_arg}" = "orgpush" ]; then
108 archive_name="orgdir"
111 cat "${config_file}" | while read line; do
112 first_char=$(echo "${line}" | cut -c1)
113 if [ "${first_char}" = "#" ]; then
116 repo="${line}:${standard_repo}"
117 archive="${repo}::${archive_name}-{utcnow:%Y-%m-%dT%H:%M}"
118 echo "Creating archive: ${archive}"
119 borg create --verbose --list "${archive}" "${to_backup}" --exclude ~/org/.git
121 elif [ "${first_arg}" = "orgpull" ]; then
122 archive_name="orgdir"
125 cat "${config_file}" | while read line; do
126 first_char=$(echo "${line}" | cut -c1)
127 if [ "${first_char}" = "#" ]; then
130 repo="${line}:${standard_repo}"
131 archive=$(borg list "${repo}" | grep "${orgdir}" | tail -1 | cut -f1 -d' ')
132 echo "Pulling archive: ${archive}"
133 borg extract --verbose "${repo}::${archive}"