commit 0277cf29e530647470583e622863f01828c5731b
parent 1861cb01d7360cbcc096ed5df7c43393eaed766c
Author: Oscar Benedito <oscar@oscarbenedito.com>
Date:   Mon, 13 Jul 2020 22:29:23 +0200

Add website-backup script

Diffstat:
Awebsite-backup/.gitignore | 2++
Awebsite-backup/website-backup.sh | 47+++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 49 insertions(+), 0 deletions(-)

diff --git a/website-backup/.gitignore b/website-backup/.gitignore @@ -0,0 +1,2 @@ +website_api_token.txt +urls.txt diff --git a/website-backup/website-backup.sh b/website-backup/website-backup.sh @@ -0,0 +1,47 @@ +#!/usr/bin/env sh +# Copyright (C) 2020 Oscar Benedito +# +# This file is part of Utilities. +# +# Utilities is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Utilities is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Utilities. If not, see <https://www.gnu.org/licenses/>. + +# Script to backup content on the Internet. It gets a list of URLs and +# destination files and puts each document in the corresponding file, +# adding a date to the filename. + +FILE_DIR="$(dirname "$(realpath "$0")")" +GOTIFY_DOMAIN="gotify.oscarbenedito.com" +API_TOKEN="$(cat "$FILE_DIR/website_api_token.txt")" +URL_FILE="$FILE_DIR/urls.txt" +BACKUP_PATH="$HOME/backups" + +save() { wget --quiet --output-document "$OUTPUT" "$URL" ; } + +error_message () { + TITLE="Website backup error" + MESSAGE="Error backing up $OUTPUT" + + curl -X POST "https://$GOTIFY_DOMAIN/message?token=$API_TOKEN" \ + -F "title=$TITLE" \ + -F "message=$MESSAGE" \ + -F "priority=5" \ + >/dev/null 2>&1 +} + +while IFS= read -r line +do + OUTPUT="$BACKUP_PATH/$(date +"%Y-%m-%d")-${line#* }" + URL="${line% *}" + save || error_message +done < "$URL_FILE"