Skip to content
Snippets Groups Projects
Select Git revision
  • bc66db612bb6f5b5e18b5e89ce5b8e57ec9b5ffb
  • master default protected
  • update_hugo_version
3 results

SetUrl.md

Blame
  • inc.sh 1.44 KiB
    #!/bin/bash
    
    if [ `whoami` != "root" ]; then
        echo "this script must be run as root"
        exit 1
    fi
    
    DIR=$(realpath $(dirname $0))
    if [ -z "$conf_file" ]; then
        conf_file="$DIR/.env"
    fi
    source $conf_file
    
    if [ -z "$log_file" ]; then
        log_file=/var/log/bckp.log
    fi
    
    
    if [ -z "$verbosity" ]; then
        verbosity="notice"
    fi
    
    if [ -z "$timeout" ]; then
        timeout=60
    fi
    
    remote="ftp://$user@$host/$remotedir/"
    
    # Exit the script and sendmail
    # $1 : exit code
    # $2 : message
    leave(){
            subject="[ `hostname` ] Backup"
            if [ $1 -eq 0 ]
            then
                    subject="$subject successful"
            else
                    subject="$subject failed"
            fi
    cat << EOF | /usr/sbin/sendmail -t root
    Subject: $subject
    
    The backup on `hostname` ended with code $1.
    
    $2
    
    For more information see $log_file
    
    Best regards,
    
    EOF
            exit $1
    }
    
    run_duplicity(){
        export PASSPHRASE="$encpass"
        export FTP_PASSWORD="$ftppass"
        set -x
        /usr/bin/duplicity --verbosity $verbosity \
            --timeout $timeout \
            $@ \
            $remote
        set +x
        unset PASSPHRASE
        unset FTP_PASSWORD
    }
    
    cleanup(){
        echo "Cleaning"
        run_duplicity cleanup --force
    }
    
    delete_old_backups(){
        echo "Removing old backups"
        run_duplicity remove-older-than $BK_FULL_LIFE --force
        run_duplicity remove-all-but-n-full $BK_KEEP_FULL --force
        collection_state
    }
    
    collection_state(){
        echo "Backups state"
        run_duplicity collection-status $@
    }