Backup with LFTP

From OpenKM Documentation
(Redirected from Backup with lftp)
Jump to: navigation, search

LFTP is a sophisticated ftp/http client, and a file transfer program supporting a number of network protocols.


Nota clasica.png This configuration does not provide incremental backups.

Remote backup with LFTP

#!/bin/bash
#
## BEGIN CONFIG ##
HOST=$(uname -n)
NOW=$(date +"%d-%m-%Y")
MYSQL_PASS=""
OPENKM_DB="okmdb"
OPENKM_HOME="/home/openkm"
TOMCAT_HOME="$OPENKM_HOME/tomcat-7.0.27"
DATABASE_EXP="$OPENKM_HOME/db"
BACKUP_DIR="ftp://user:password@ftp.server/backup"
## END CONFIG ##

if [ $(id -u) != 0 ]; then echo "You should run this script as root"; exit; fi

echo -e "### BEGIN: $(date +"%x %X") ###\n"
rm -rf $DATABASE_EXP
mkdir -p $DATABASE_EXP

# Stop Tomcat
/etc/init.d/tomcat stop

# Clean logs
echo "Clean Tomcat temporal files."
rm -rf $TOMCAT_HOME/logs/*
rm -rf $TOMCAT_HOME/temp/*
rm -rf $TOMCAT_HOME/work/Catalina/localhost

# Backup de MySQL
if [ -n "$MYSQL_PASS" ]; then
  echo "* Backuping MySQL data from $OPENKM_DB...";
  mysqldump -h localhost -u root -p$MYSQL_PASS $OPENKM_DB | gzip -9 > $DATABASE_EXP/mysql_$OPENKM_DB.gz
  echo "-------------------------------------";
fi

# Start FTP backup
lftp $BACKUP_DIR -e "mkdir $NOW; mirror --reverse $OPENKM_HOME $NOW; exit"

# Start Tomcat
/etc/init.d/tomcat start
echo -e "\n### END: $(date +"%x %X") ###"