#!/bin/bash #Script to save all Dolbarr data ######################## VARIABLES ################################# backUpPath=/etc/doli_demo/BackUp configFile=/etc/doli_demo/htdocs/conf.php #delete the archive older than X days daysToKeep=20 ############################ CODE ################################## getvar() { local var="$1" sed '/^'"$var"' *= *'\''\(.*\)'\''.*$/!d;s//\1/g' "$configFile" } documentPath="$(getvar '$dolibarr_main_data_root')" if [ -z "$documentPath" ] then echo document path not set exit fi dbhost="$(getvar '$dolibarr_main_db_host')" if [ -z "$dbhost" ] then echo database host not set exit fi dbport="$(getvar '$dolibarr_main_db_port')" if [ -z "$dbport" ] then echo database port not set exit fi dbuser="$(getvar '$dolibarr_main_db_user')" if [ -z "$dbuser" ] then echo database user not set exit fi dbname="$(getvar '$dolibarr_main_db_name')" if [ -z "$dbname" ] then echo database name not set exit fi dbpass="$(getvar '$dolibarr_main_db_pass')" if [ -z "$dbpass" ] then echo database password not set exit fi #Archive creation #temp folder creation tempDir=`mktemp -d` #copy of the dolibarr Config file cp $configFile $tempDir # SQL dump mysqldump -h $dbhost -P $dbport -u $dbuser --password=$dbpass --result-file=$tempDir/$dbname.sql $dbname # Documents cp -R $documentPath/ $tempDir # 7z command 7z a $backUpPath/$(date +%Y%m%d-%H%M)_dolibarr.7z $tempDir/* # Cleanup rm -rf $tempDir find $backUpPath/ -type f -mtime +$daysToKeep -exec rm {} \;