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

Code refactor + archive_path + logfile + verbosity

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