This commit is contained in:
Adrian Amaglio 2023-02-02 10:45:52 +01:00
commit 7ed4949630
3 changed files with 52 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
.env
db.sqlite

41
backup.sh Executable file
View File

@ -0,0 +1,41 @@
#!/bin/bash
set -euo pipefail
if [ "$#" -ne 1 ] ; then
usage "$0 <id>"
exit 1
fi
id="$1"
function extract() {
if [ "$#" -ne 1 ] ; then
usage "$0 <key>"
exit 1
fi
echo "select $1 from files where id=$id" | sqlite3 db.sqlite
}
# Extract variables from database
username="$(extract username)"
password="$(extract password)"
server="$(extract server)"
export_path="$(extract export_path)"
backup_url="$(extract backup_url)"
# Create destination directory (fails if exists)
curl -u "$username:$password" -X MKCOL "$server/remote.php/dav/files/$username/$export_path"
name="$(basename "$backup_url")"
# Insert date before file extention
new_name="$(echo $name | sed "s/\(\.[^\.]\+\)$/_$(date +%F)\1/")"
echo "Downloading $backup_url"
tmp="$(mktemp)"
curl "$backup_url" > "$tmp"
echo "Uploading as $export_path/$new_name"
curl -u "$username:$password" -X PUT --data-binary "@$tmp" "$server/remote.php/dav/files/$username/$export_path/$new_name"
rm "$tmp"

9
initdb.sql Normal file
View File

@ -0,0 +1,9 @@
CREATE TABLE files (
id INTEGER PRIMARY KEY AUTOINCREMENT,
username text NOT NULL,
password text NOT NULL,
server text NOT NULL,
export_path text NOT NULL,
backup_url text NOT NULL,
crontab_time text NOT NULL
)