5 config_file="${HOME}/.borgrepos"
8 echo "Need operation as argument, one of:"
12 echo "export_keyfiles"
22 if [ "${#BORG_PASSPHRASE}" -eq 0 ]; then
24 printf "Borg passphrase: "
28 export BORG_PASSPHRASE="${password}"
32 if [ ! -f "${config_file}" ]; then
33 echo '# file read ends at last newline' >> "${config_file}"
35 if [ "$#" -lt 1 ]; then
40 if [ "${first_arg}" = "init" ]; then
41 if [ ! "$#" -eq 1 ]; then
42 echo "Need exactly one argument: target of form user@server"
46 echo "Initializing: ${target}"
47 borg init --verbose --encryption=keyfile "${target}:${standard_repo}"
48 tmp_file="/tmp/new_borgrepos"
49 echo "${target}" > "${tmp_file}"
50 cat "${config_file}" >> "${tmp_file}"
51 cp "${tmp_file}" "${config_file}"
52 elif [ "${first_arg}" = "store" ]; then
53 if [ ! "$#" -eq 2 ]; then
54 echo "Need precisely two arguments: archive name and path to archive."
61 cat "${config_file}" | while read line; do
62 first_char=$(echo "${line}" | cut -c1)
63 if [ "${first_char}" = "#" ]; then
66 repo="${line}:${standard_repo}"
67 archive="${repo}::${archive_name}-{utcnow:%Y-%m-%dT%H:%M}"
68 echo "Creating archive: ${archive}"
69 borg create --verbose --list "${archive}" "${to_backup}"
71 elif [ "${first_arg}" = "check" ]; then
72 if [ ! "$#" -eq 0 ]; then
73 echo "Need no arguments"
77 cat "${config_file}" | while read line; do
78 first_char=$(echo "${line}" | cut -c1)
79 if [ "${first_char}" = "#" ]; then
82 repo="${line}:${standard_repo}"
83 echo "Checking repo: ${repo}"
84 borg check --verbose "${repo}"
86 elif [ "${first_arg}" = "export_keyfiles" ]; then
87 if [ ! "$#" -eq 1 ]; then
88 echo "Need output tar file name."
92 tmp_dir="${HOME}/.borgtmp"
93 keyfiles_dir="${tmp_dir}/borg_keyfiles"
94 mkdir -p "${keyfiles_dir}"
95 cat "${config_file}" | while read line; do
96 first_char=$(echo "${line}" | cut -c1)
97 if [ "${first_char}" = "#" ]; then
100 repo="${line}:${standard_repo}"
101 borg key export "${repo}" "${keyfiles_dir}/${line}"
105 target=$(basename "${keyfiles_dir}")
106 tar cf "${tar_target}" "${target}"
107 mv "${tar_target}" "${cur_dir}"
110 elif [ "${first_arg}" = "orgpush" ]; then
111 archive_name="orgdir"
114 cat "${config_file}" | while read line; do
115 first_char=$(echo "${line}" | cut -c1)
116 if [ "${first_char}" = "#" ]; then
119 repo="${line}:${standard_repo}"
120 archive="${repo}::${archive_name}-{utcnow:%Y-%m-%dT%H:%M}"
121 echo "Creating archive: ${archive}"
122 borg create --verbose --list "${archive}" "${to_backup}" --exclude ~/org/.git
124 elif [ "${first_arg}" = "orgpull" ]; then
125 archive_name="orgdir"
128 cat "${config_file}" | while read line; do
129 first_char=$(echo "${line}" | cut -c1)
130 if [ "${first_char}" = "#" ]; then
133 repo="${line}:${standard_repo}"
134 archive=$(borg list "${repo}" | grep "${orgdir}" | tail -1 | cut -f1 -d' ')
135 echo "Pulling archive: ${archive}"
136 borg extract --verbose "${repo}::${archive}"