commit 1abf28cdf58cc5e1dba3cde66aae1bbf28aeee42 Author: zankia Date: Sun Feb 18 22:27:17 2024 +0100 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c2e67cc --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +*.swp +test + +backup.list +config.properties diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..5439c5d --- /dev/null +++ b/LICENSE @@ -0,0 +1,9 @@ +MIT License + +Copyright (c) 2024 zankia + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/autoBackup b/autoBackup new file mode 100755 index 0000000..3e3ac55 --- /dev/null +++ b/autoBackup @@ -0,0 +1,39 @@ +#! /bin/bash + +if [ -f config.properties ]; then + source config.properties +elif [ -f /etc/autoBackup/config.properties ]; then + source /etc/autoBackup/config.properties +else + >&2 echo Could not find config.properties + exit 1 +fi + +if [ -f backup.list ]; then + SOURCE_LIST_FILE=backup.list +elif [ -f /etc/autoBackup/backup.list ]; then + SOURCE_LIST_FILE=/etc/autoBackup/backup.list +else + >&2 echo Could not find backup.list + exit 1 +fi + +mkdir -p "$BACKUP_DIR" + +DATE=$(date "+%Y%m%d") + +while IFS= read -r SOURCE; do + SOURCE="${SOURCE%%#*}" + SOURCE=$(echo "$SOURCE" | sed -re 's/^[[:blank:]]+|[[:blank:]]+$//g') + + if [ -z "$SOURCE" ]; then + continue + fi + + rsync --archive --relative --link-dest="$BACKUP_DIR/previous" "$SOURCE" "$BACKUP_DIR/backup_$DATE" +done <"$SOURCE_LIST_FILE" + +rm "$BACKUP_DIR/previous" +ln -s "backup_$DATE" "$BACKUP_DIR/previous" + +find "$BACKUP_DIR" -maxdepth 1 -type d -mtime "+$RETENTION_DAYS" -exec rm -r {} \; diff --git a/backup.list.default b/backup.list.default new file mode 100644 index 0000000..653701f --- /dev/null +++ b/backup.list.default @@ -0,0 +1 @@ +# Mettre ici tous les dossiers à sauvegarder. Un dossier par ligne diff --git a/config.properties.default b/config.properties.default new file mode 100644 index 0000000..bc7ea5c --- /dev/null +++ b/config.properties.default @@ -0,0 +1,2 @@ +BACKUP_DIR="/backup" +RETENTION_DAYS=364