diff --git a/bootstrap.sh b/bootstrap.sh index 76d39fd..10e5762 100644 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -1,222 +1,231 @@ #!/bin/bash ### # Part of a stupid script to backup some stuff # # This bootstrap.sh file does nothing by itself but loads useful stuff. # # This file is loaded from 'backup-everything.sh' or 'rotate.sh' # # Author: 2020, 2021 Valerio Bozzolan # License: MIT ## # current directory DIR="${BASH_SOURCE%/*}" if [[ ! -d "$DIR" ]]; then DIR="$PWD"; fi # check if the standard input is not a terminal INTERACTIVE= if [ -t 0 ]; then INTERACTIVE=1 fi # # Check if this is the quiet mode # # Default - not quite. # # Actually we are in quiet mode if it's not interactive. # This lazy behavior is to avoid stupid emails from the crontab # without the need to specify some --quiet etc. # Note that in quiet mode only WARN and ERROR messages are shown. # I've not created a --quiet flag because nobody is needing it. # # Edit your options - do not edit here. # #QUIET= # # Eventually write a log file # # Default - don't write. # # Edit your options - do not edit here. # #WRITELOG= # path to the instructions file INSTRUCTIONS="$DIR/backup-instructions.conf" # path to the configuration file CONFIG="$DIR/options.conf" # no config no party if [ ! -f $CONFIG ]; then echo "missing options expected in $CONFIG" exit 1 fi # no instructions no party if [ ! -f $INSTRUCTIONS ]; then echo "missing instructions expected in $INSTRUCTIONS" exit 1 fi # default mysql commands # --batch: avoid fancy columns (auto-enabled, but better to specify it) # --silent: avoid the column name to be included MYSQL="mysql --batch --silent" MYSQLDUMP="mysqldump" # default rsync command # --archive: Try to keep all the properties # --fuzzy: Try to check if a file was renamed instead of delete and download a new one # It's efficient for example with log rotated files. # --delete: Delete the destination files if not present in the source # NOTE: we want this behaviour but it's not a good idea toghether with --fuzzy # that's why we do not use --delete but we use the next flags # --delay-updates Put all updated files into place at end (useful with fuzzy and delete modes) # --delete-delay Delete after everything (useful with fuzzy and delete modes) +# NOTE: sometime some data is kept in damn .~tmp~ directories +# So we are deprecating --delete-delay, and going back to --delete +# and so removing --fuzzy # --hard-links Try to look for hard links during the transfer to do not copy separate files -RSYNC="rsync --archive --fuzzy --delay-updates --delete-delay --hard-links" +#RSYNC="rsync --archive --fuzzy --delay-updates --delete-delay --hard-links" + +# default rsync command +# --archive: Try to keep all the properties +# --delete: Delete the destination files if not present in the source +# --hard-links Try to look for hard links during the transfer to do not copy separate files +RSYNC="rsync --archive --delete --hard-links" # rsync used in remote transfers # --compress Use more CPU to save network bandwidth RSYNC_REMOTE="$RSYNC --compress" # default base backup directory for all backups BASE="/home/backups" # default box name BOX="$(hostname)" # set to 1 to avoid any disservice (e.g. systemctl stop/start) NO_DISSERVICE= # set to 1 to do nothing PORCELAIN= # include the configuration to eventually override some options . "$CONFIG" # as default, if not interactive, set quite mode if [ -z "$QUIET" ] && [ "$INTERACTIVE" != 1 ]; then QUIET=1 fi # as default, if quiet, write in the log if [ -z "$WRITELOG" ] && [ "$QUIET" = 1 ]; then WRITELOG=1 fi # full pathnames to the backup directories BASEBOX="$BASE/$BOX" DAILY="$BASEBOX/daily" DAILY_FILES="$DAILY/files" DAILY_DATABASES="$DAILY/databases" DAILY_LASTLOG="$DAILY/last.log" DAILY_LASTTIME="$DAILY/last.timestamp" # apply the porcelain to the rsync command if [ "$PORCELAIN" = 1 ]; then RSYNC="$RSYNC --dry-run" RSYNC_REMOTE="$RSYNC_REMOTE --dry-run" fi # set default backup_last_log() lines if [ -z "$BACKUP_LAST_LOG_LINES" ]; then BACKUP_LAST_LOG_LINES=2000 fi ### # Print something # # It also put the message in the backup directory # # @param string severity # @param string message # function printthis() { local msg="[$(date)][$1] $2" # print to standard output if it's not in quiet mode if [ "$QUIET" != 1 ]; then echo "$msg" fi # put in the log file if possible if [ -f "$DAILY_LASTLOG" ] && [ "$WRITELOG" = 1 ]; then echo "$msg" >> "$DAILY_LASTLOG" fi } ### # Run an rsync # function copy() { # show what we are doing log "copy $*" # run the rsync command if [ "$PORCELAIN" != 1 ]; then $RSYNC $@ fi } ### # Remove a pathname # function drop() { # show what we are doing log "drop $*" # well, proceed... finger crossed... with some protections if [ "$PORCELAIN" != 1 ]; then rm --recursive --force --one-file-system --preserve-root -- $@ fi } ### # Move something somewhere # function move() { # show what we are doing log "move $*" if [ "$PORCELAIN" != 1 ]; then mv --force $@ fi } ### # Print a information message # # @param msg Message # function log() { printthis INFO "$1" } ### # Print a warning message # # @param msg Message # function warn() { printthis WARN "$1" } ### # Print an error message # # @param msg Message # function error() { printthis ERROR "$1" }