Skip to content
Snippets Groups Projects
Select Git revision
  • test-fix-cache-issues
  • master default protected
  • add-action-params-in-backup
3 results

backup.sh

Blame
  • David Beniamine's avatar
    David Beniamine authored
    358ee631
    History
    backup.sh 1004 B
    #!/bin/bash
    
    DIR=$(realpath $(dirname $0))
    if [ ! -z "$1" ]; then
       conf_file=$1
       shift
    fi
    source $DIR/inc.sh
    exec &> >(tee -a "$log_file")
    
    exit_on_fail(){
            [ $1 -ne 0 ] && leave $@
            echo "Done"
    }
    
    retrie_on_fail(){
            cat <<EOF | lftp $host
    user $user $ftppass
    
    rm -rf $remotedir
    mkdir $remotedir
    EOF
    backup "cleaned"
    leave $?
    }
    
    backup(){
        retries=$1
        shift
    
        cleanup
        echo "Removing old backups"
        delete_old_backups
    
        echo "Running pre_actions"
        pre_actions
        exit_on_fail $? "Pre_action failed"
        echo "Creating encrypted incremental backup: $bckplist "
        run_duplicity --full-if-older-than $BK_FULL_FREQ \
            --include ${bckplist// / --include } \
            --exclude /root/.cache/duplicity/ \
            /
        ret=$?
        if [ -z "$retries" ]
        then
            retrie_on_fail $ret "Duplicity failed"
        else
            exit_on_fail $ret "Duplicity failed"
        fi
    
        echo "Backup completed"
    
        collection_state
        echo "All Done"
    }
    backup
    leave $?