Skip to content
Snippets Groups Projects
Verified Commit 5f4fef7b authored by David Beniamine's avatar David Beniamine
Browse files

Code refactor + archive_path + logfile + verbosity

parent 33c3ff25
No related branches found
No related tags found
No related merge requests found
......@@ -5,6 +5,10 @@ encpass='CHANGEME'
bckplist="/root /etc /srv /var/www /usr /lib /opt /var/opt /var/lib/docker/volumes/ /home"
remotedir="bckp_`hostname`"
verbosity="info"
# Set an arcihve directory, subdir of /root/.cache/duplicity
archive_dir=""
log_file=/var/log/bckp.log
BK_FULL_FREQ="3W" # create a new full backup every...
......
......@@ -6,6 +6,7 @@ if [ ! -z "$1" ]; then
shift
fi
source $DIR/inc.sh
exec &> >(tee -a "$log_file")
exit_on_fail(){
[ $1 -ne 0 ] && leave $@
......@@ -24,30 +25,21 @@ leave $?
}
backup(){
retries=$1
shift
export PASSPHRASE="$encpass"
export FTP_PASSWORD="$ftppass"
#set -x
cleanup
echo "Removing old backups"
/usr/bin/duplicity remove-older-than $BK_FULL_LIFE \
--force ftp://$user@$host/$remotedir/
/usr/bin/duplicity remove-all-inc-of-but-n-full $BK_KEEP_FULL \
--force ftp://$user@$host/$remotedir/
/usr/bin/duplicity remove-all-but-n-full $BK_KEEP_FULL \
--force ftp://$user@$host/$remotedir/
delete_old_backups
echo "Running pre_actions"
pre_actions
exit_on_fail $? "Pre_action failed"
echo "Creating encrypted incremental backup: $bckplist "
/usr/bin/duplicity \
--full-if-older-than $BK_FULL_FREQ \
run_duplicity --full-if-older-than $BK_FULL_FREQ \
--include ${bckplist// / --include } \
--exclude '**' \
/ ftp://$user@$host/$remotedir/
--exclude /root/.cache/duplicity/ \
/
ret=$?
if [ -z "$retries" ]
then
......@@ -58,15 +50,7 @@ backup(){
echo "Backup completed"
echo "Cleaning"
/usr/bin/duplicity cleanup --force --extra-clean ftp://$user@$host/$remotedir/
echo "Removing backup cache"
rm -rf /root/.cache/duplicity/
echo "Backups state"
/usr/bin/duplicity collection-status ftp://$user@$host/$remotedir/
#set +x
unset PASSPHRASE
unset FTP_PASSWORD
collection_state
echo "All Done"
}
backup
......
......@@ -7,28 +7,8 @@ if [ ! -z "$1" ]; then
fi
source $DIR/inc.sh
export PASSPHRASE="$encpass"
export FTP_PASSWORD="$ftppass"
#set -x
delete_old_backups
echo "Removing old backups"
/usr/bin/duplicity remove-older-than $BK_FULL_LIFE \
--force ftp://$user@$host/$remotedir/
/usr/bin/duplicity remove-all-inc-of-but-n-full $BK_KEEP_FULL \
--force ftp://$user@$host/$remotedir/
/usr/bin/duplicity remove-all-but-n-full $BK_KEEP_FULL \
--force ftp://$user@$host/$remotedir/
/usr/bin/duplicity collection-status ftp://$user@$host/$remotedir/
echo "Cleaning"
/usr/bin/duplicity cleanup --force --extra-clean ftp://$user@$host/$remotedir/
echo "Removing backup cache"
rm -rf /root/.cache/duplicity/
echo "Backups state"
/usr/bin/duplicity collection-status ftp://$user@$host/$remotedir/
#set +x
unset PASSPHRASE
unset FTP_PASSWORD
cleanup
collection_state
echo "All Done"
leave 0
......@@ -2,10 +2,4 @@
DIR=$(realpath $(dirname $0))
source $DIR/inc.sh
export PASSPHRASE="$encpass"
export FTP_PASSWORD="$ftppass"
/usr/bin/duplicity collection-status ftp://$user@$host/$remotedir/
unset PASSPHRASE
unset FTP_PASSWORD
collection_state
#!/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
remote="ftp://$user@$host/$remotedir/"
# Exit the script and sendmail
# $1 : exit code
# $2 : message
......@@ -32,8 +48,31 @@ EOF
exit $1
}
if [ `whoami` != "root" ]
then
echo "this script must be run as root"
exit 1
fi
run_duplicity(){
export PASSPHRASE="$encpass"
export FTP_PASSWORD="$ftppass"
set -x
/usr/bin/duplicity --verbosity $verbosity \
$@ \
$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
}
......@@ -2,10 +2,4 @@
DIR=$(realpath $(dirname $0))
source $DIR/inc.sh
export PASSPHRASE="$encpass"
export FTP_PASSWORD="$ftppass"
/usr/bin/duplicity list-current-files ftp://$user@$host/$remotedir/
unset PASSPHRASE
unset FTP_PASSWORD
run_duplicity list-current-files
......@@ -36,7 +36,7 @@ source $DIR/inc.sh
export PASSPHRASE="$encpass"
export FTP_PASSWORD="$ftppass"
/usr/bin/duplicity --file-to-restore $delay "$restore_path" ftp://$user@$host/$remotedir/ "$destination_path"
/usr/bin/duplicity --verbosity $verbosity --file-to-restore $delay "$restore_path" $remote "$destination_path"
unset PASSPHRASE
unset FTP_PASSWORD
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment