Difference between revisions of "Backup with rdiff-backup"

From OpenKM Documentation
Jump to: navigation, search
m
m (Remote backup to SMB or CIFS with rdiff-backup)
 
(51 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 +
{{TOCright}} __TOC__
 +
 
rdiff-backup backs up one directory to another, possibly over a network. The target directory ends up a copy of the source directory, but extra reverse diffs are stored in a special subdirectory of that target directory, so you can still recover files lost some time ago. The idea is to combine the best features of a mirror and an incremental backup. rdiff-backup also preserves subdirectories, hard links, dev files, permissions, uid/gid ownership, modification times, extended attributes, acls, and resource forks. Also, rdiff-backup can operate in a bandwidth efficient manner over a pipe, like rsync. Thus you can use rdiff-backup and ssh to securely back a hard drive up to a remote location, and only the differences will be transmitted.
 
rdiff-backup backs up one directory to another, possibly over a network. The target directory ends up a copy of the source directory, but extra reverse diffs are stored in a special subdirectory of that target directory, so you can still recover files lost some time ago. The idea is to combine the best features of a mirror and an incremental backup. rdiff-backup also preserves subdirectories, hard links, dev files, permissions, uid/gid ownership, modification times, extended attributes, acls, and resource forks. Also, rdiff-backup can operate in a bandwidth efficient manner over a pipe, like rsync. Thus you can use rdiff-backup and ssh to securely back a hard drive up to a remote location, and only the differences will be transmitted.
  
 
{{Note|rdiff-backup from Debian throws a warning due to a deprecated method [[http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=590107 os.popen2 is deprecated]], which can be hidden following the steps at [http://www.linuxinsight.com/how-to-shut-up-python-deprecation-warnings.html How to shut up Python deprecation warnings].}}
 
{{Note|rdiff-backup from Debian throws a warning due to a deprecated method [[http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=590107 os.popen2 is deprecated]], which can be hidden following the steps at [http://www.linuxinsight.com/how-to-shut-up-python-deprecation-warnings.html How to shut up Python deprecation warnings].}}
 +
 +
{{Note|If you need to backup to CIFS (SMB, Samba) or Mac's HFS, please take a look at [http://rdiff-backup.nongnu.org/FAQ.html rdiff-backup FAQ].}}
 +
 +
{{Advice|See also [[Backup restoring]].}}
 +
 +
More info about rdiff-backup:
 +
* [http://rdiff-backup.nongnu.org/ rdiff-backup home page]
 +
* [http://wiki.rdiff-backup.org/wiki/index.php/Main_Page rdiff-backup wiki]
 +
* [http://www.mad-hacking.net/documentation/linux/reliability/backup/using-rdiff-backup-remote.xml Using rdiff-backup for remote backups]
 +
* [http://www.hskupin.info/2012/01/11/suppress-socket-warnings-when-using-rdiff-backup/ Suppress socket warnings when using rdiff-backup]
  
 
== Remote backup with rdiff-backup ==
 
== Remote backup with rdiff-backup ==
Line 19: Line 31:
 
# Backup and purge old backups
 
# Backup and purge old backups
 
rdiff-backup --remove-older-than 30B backup@server::$BACKUP_DIR/$HOST
 
rdiff-backup --remove-older-than 30B backup@server::$BACKUP_DIR/$HOST
rdiff-backup -v 3 --print-statistics --exclude /media --exclude /mnt \
+
rdiff-backup -v 3 --print-statistics --include $FILES --exclude '**' / backup@server::$BACKUP_DIR/$HOST
  --include $FILES --exclude '**' / backup@server::$BACKUP_DIR/$HOST
 
  
 
# Start JBoss
 
# Start JBoss
Line 31: Line 42:
 
echo "=================================";
 
echo "=================================";
 
</source>
 
</source>
 
More info about rdiff-backup:
 
* [http://rdiff-backup.nongnu.org/ rdiff-backup home page]
 
* [http://wiki.rdiff-backup.org/wiki/index.php/Main_Page rdiff-backup wiki]
 
  
 
== Local backup to USB disk with rdiff-backup ==
 
== Local backup to USB disk with rdiff-backup ==
Line 47: Line 54:
 
HOST=$(uname -n)
 
HOST=$(uname -n)
 
MYSQL_PASS=""
 
MYSQL_PASS=""
 +
OPENKM_DB="okmdb"
 +
OPENKM_HOME="/home/openkm"
 +
TOMCAT_HOME="$OPENKM_HOME/tomcat-7.0.27"
 +
DATABASE_EXP="$OPENKM_HOME/db"
 +
BACKUP_DIR="/mnt/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
 +
 +
# Mount disk
 +
if mount | grep "$BACKUP_DIR type" > /dev/null; then
 +
  echo "$BACKUP_DIR already mounted";
 +
else
 +
  mount "$BACKUP_DIR";
 +
fi
 +
 +
# 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 > $DATABASE_EXP/mysql_$OPENKM_DB.sql
 +
  echo "-------------------------------------";
 +
fi
 +
 +
# Backup and purge old backups
 +
rdiff-backup --remove-older-than 30B $BACKUP_DIR/$HOST
 +
rdiff-backup -v 3 --print-statistics --include $OPENKM_HOME --exclude '**' / $BACKUP_DIR/$HOST
 +
 +
# Start Tomcat
 +
/etc/init.d/tomcat start
 +
echo -e "\n### END: $(date +"%x %X") ###"
 +
 +
# Status
 +
echo "=================================";
 +
rdiff-backup --list-increment-sizes $BACKUP_DIR/$HOST
 +
echo "*********************************";
 +
df -h | grep "$BACKUP_DIR"
 +
echo "=================================";
 +
 +
# Umount disk
 +
sync
 +
umount "$BACKUP_DIR"
 +
</source>
 +
 +
== Remote backup to SMB or CIFS with rdiff-backup ==
 +
If you are runing Ubuntu, install '''cifs-utils''' package.
 +
 +
<source lang="bash">
 +
#!/bin/bash
 +
#
 +
## BEGIN CONFIG ##
 +
HOST=$(uname -n)
 +
MYSQL_PASS=""
 +
OPENKM_DB="okmdb"
 
OPENKM_HOME="/home/openkm"
 
OPENKM_HOME="/home/openkm"
JBOSS_HOME="$OPENKM_HOME/jboss-4.2.3.GA"
+
TOMCAT_HOME="$OPENKM_HOME/tomcat-7.0.27"
 
DATABASE_EXP="$OPENKM_HOME/db"
 
DATABASE_EXP="$OPENKM_HOME/db"
 
BACKUP_DIR="/mnt/backup"
 
BACKUP_DIR="/mnt/backup"
Line 63: Line 136:
 
   echo "$BACKUP_DIR already mounted";
 
   echo "$BACKUP_DIR already mounted";
 
else
 
else
   mount $BACKUP_DIR;
+
  echo "Mounting $BACKUP_DIR ...";
 +
   mount -t cifs //REMOTE_SERVER/REMOTE_DIR $BACKUP_DIR -o username=REMOTE_USER,password=REMOTE_PASSWORD,iocharset=utf8,file_mode=0777,dir_mode=0777
 
fi
 
fi
  
# Stop JBoss
+
# Stop Tomcat
/etc/init.d/jboss stop
+
/etc/init.d/tomcat stop
  
 
# Clean logs
 
# Clean logs
echo "Clean JBoss temporal files."
+
#echo "Clean Tomcat temporal files."
rm -rf $JBOSS_HOME/server/default/log
+
#rm -rf $TOMCAT_HOME/logs/*
rm -rf $JBOSS_HOME/server/default/tmp
+
#rm -rf $TOMCAT_HOME/temp/*
rm -rf $JBOSS_HOME/server/default/work
+
#rm -rf $TOMCAT_HOME/work/Catalina/localhost
  
 
# Backup de MySQL
 
# Backup de MySQL
 
if [ -n "$MYSQL_PASS" ]; then
 
if [ -n "$MYSQL_PASS" ]; then
   MYSQL_DBS=$(mysqlshow -h localhost -u root -p$MYSQL_PASS | awk '(NR > 2) && (/[a-zA-Z0-9]+[ ]+[|]/) && ($2 != "mysql") && ($2 != "test") && ($2 != "information_schema") { print $2 }');
+
   echo "* Backuping MySQL data from $OPENKM_DB..."
 
+
  mysqldump -h localhost -u root -p$MYSQL_PASS $OPENKM_DB > $DATABASE_EXP/mysql_$OPENKM_DB.sql
  for DB in $MYSQL_DBS ; do
 
    echo "* Backuping MySQL data from $DB...";
 
    mysqldump -h localhost -u root -p$MYSQL_PASS $DB > $DATABASE_EXP/mysql_$DB.sql
 
  done
 
 
   echo "-------------------------------------";
 
   echo "-------------------------------------";
 
fi
 
fi
Line 88: Line 158:
 
# Backup and purge old backups
 
# Backup and purge old backups
 
rdiff-backup --remove-older-than 30B $BACKUP_DIR/$HOST
 
rdiff-backup --remove-older-than 30B $BACKUP_DIR/$HOST
rdiff-backup -v 3 --print-statistics --exclude /media --exclude /mnt \
+
rdiff-backup -v 3 --print-statistics --include $OPENKM_HOME --exclude '**' / $BACKUP_DIR/$HOST
  --include $OPENKM_HOME --exclude '**' / $BACKUP_DIR/$HOST
 
  
# Start JBoss
+
# Start Tomcat
/etc/init.d/jboss start
+
/etc/init.d/tomcat start
 
echo -e "\n### END: $(date +"%x %X") ###"
 
echo -e "\n### END: $(date +"%x %X") ###"
  
Line 104: Line 173:
 
# Umount disk
 
# Umount disk
 
sync
 
sync
umount $BACKUP_DIR
+
umount "$BACKUP_DIR"
 +
</source>
 +
 
 +
== Remote backup with rdiff-backup (JBoss) ==
 +
<source lang="bash">
 +
#!/bin/bash
 +
#
 +
# @weekly /root/backup.sh
 +
#
 +
## BEGIN CONFIG ##
 +
HOST=$(uname -n)
 +
MYSQL_PASS=""
 +
OPENKM_DB="okmdb"
 +
OPENKM_HOME="/home/openkm"
 +
TOMCAT_HOME="$OPENKM_HOME/tomcat-7.0.27"
 +
DATABASE_EXP="$OPENKM_HOME/db"
 +
BACKUP_DST="user@server::/path/to/backup/$HOST"
 +
## END CONFIG ##
 +
 
 +
echo -e "### BEGIN: $(date +"%x %X") ###\n"
 +
rm -rf $DATABASE_EXP
 +
mkdir -p $DATABASE_EXP
 +
 +
# Stop JBoss
 +
/etc/init.d/jboss stop
 +
 
 +
# Clean logs
 +
echo "Clean JBoss temporal files."
 +
# rm -rf $JBOSS_HOME/server/default/log
 +
rm -rf $JBOSS_HOME/server/default/tmp
 +
rm -rf $JBOSS_HOME/server/default/work
 +
rm -rf $JBOSS_HOME/server/default/data/wsdl
 +
 
 +
# 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 > $DATABASE_EXP/mysql_$OPENKM_DB.sql
 +
  echo "-------------------------------------";
 +
fi
 +
 
 +
# Backup and purge old backups
 +
rdiff-backup --remove-older-than 30B $BACKUP_DST
 +
rdiff-backup -v 3 --print-statistics --include $OPENKM_HOME --exclude '**' / $BACKUP_DST
 +
 
 +
# Start JBoss
 +
/etc/init.d/jboss start
 +
echo -e "\n### END: $(date +"%x %X") ###"
 +
 +
# Status
 +
echo "=================================";
 +
rdiff-backup --list-increment-sizes $BACKUP_DST
 +
echo "=================================";
 
</source>
 
</source>
  
Be sure to have the last JBoss startup script, otherwise use this piece of code to ensure that JBoss is stopped before backuping the files:
+
== Remote backup with rdiff-backup (Tomcat - MySQL) ==
 +
<source lang="bash">
 +
#!/bin/bash
 +
#
 +
# @weekly /root/backup.sh
 +
#
 +
## BEGIN CONFIG ##
 +
HOST=$(uname -n)
 +
MYSQL_PASS=""
 +
OPENKM_DB="okmdb"
 +
OPENKM_HOME="/home/openkm"
 +
TOMCAT_HOME="$OPENKM_HOME/tomcat-7.0.27"
 +
DATABASE_EXP="$OPENKM_HOME/db"
 +
BACKUP_DST="user@server::/path/to/backup/$HOST"
 +
## END CONFIG ##
 +
 
 +
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 > $DATABASE_EXP/mysql_$OPENKM_DB.sql
 +
  echo "-------------------------------------";
 +
fi
 +
 +
# Backup and purge old backups
 +
rdiff-backup --remove-older-than 30B $BACKUP_DST
 +
rdiff-backup -v 3 --print-statistics --include $OPENKM_HOME --exclude '**' / $BACKUP_DST
 +
 +
# Start Tomcat
 +
/etc/init.d/tomcat start
 +
echo -e "\n### END: $(date +"%x %X") ###"
 +
 +
# Status
 +
echo "=================================";
 +
rdiff-backup --list-increment-sizes $BACKUP_DST
 +
echo "=================================";
 +
</source>
 +
 +
== Remote backup with rdiff-backup (Tomcat - PostgreSQL) ==
 
<source lang="bash">
 
<source lang="bash">
while [ "$(ps -ef | grep java | grep jboss | wc -l)" -gt "0" ]; do
+
#!/bin/bash
  sleep 5; echo ".";
+
#
done
+
# @weekly /root/backup.sh
 +
#
 +
## BEGIN CONFIG ##
 +
HOST=$(uname -n)
 +
OPENKM_DB="okmdb"
 +
OPENKM_HOME="/home/openkm"
 +
TOMCAT_HOME="$OPENKM_HOME/tomcat-7.0.27"
 +
DATABASE_EXP="$OPENKM_HOME/db"
 +
BACKUP_DST="user@server::/path/to/backup/$HOST"
 +
## END CONFIG ##
 +
 
 +
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 PostgreSQL
 +
echo "* Backuping PostgreSQL data from $OPENKM_DB..."
 +
su postgres -c "pg_dump $OPENKM_DB" > $DATABASE_EXP/pg_$OPENKM_DB.sql
 +
 
 +
# Databases optimizations
 +
su postgres -c "vacuumdb -a -z" > /dev/null
 +
su postgres -c "reindexdb -a -q" 2> /dev/null
 +
 
 +
echo "-------------------------------------"
 +
 +
# Backup and purge old backups
 +
rdiff-backup --remove-older-than 30B $BACKUP_DST
 +
rdiff-backup -v 3 --print-statistics --include $OPENKM_HOME --exclude '**' / $BACKUP_DST
 +
 +
# Start Tomcat
 +
/etc/init.d/tomcat start
 +
echo -e "\n### END: $(date +"%x %X") ###"
 +
 +
# Status
 +
echo "=================================";
 +
rdiff-backup --list-increment-sizes $BACKUP_DST
 +
echo "=================================";
 
</source>
 
</source>
  
 
[[Category: Installation Guide]]
 
[[Category: Installation Guide]]
[[Category: OKM Network]]
 

Latest revision as of 10:10, 3 February 2015

rdiff-backup backs up one directory to another, possibly over a network. The target directory ends up a copy of the source directory, but extra reverse diffs are stored in a special subdirectory of that target directory, so you can still recover files lost some time ago. The idea is to combine the best features of a mirror and an incremental backup. rdiff-backup also preserves subdirectories, hard links, dev files, permissions, uid/gid ownership, modification times, extended attributes, acls, and resource forks. Also, rdiff-backup can operate in a bandwidth efficient manner over a pipe, like rsync. Thus you can use rdiff-backup and ssh to securely back a hard drive up to a remote location, and only the differences will be transmitted.


Nota clasica.png rdiff-backup from Debian throws a warning due to a deprecated method [os.popen2 is deprecated], which can be hidden following the steps at How to shut up Python deprecation warnings.


Nota clasica.png If you need to backup to CIFS (SMB, Samba) or Mac's HFS, please take a look at rdiff-backup FAQ.


Nota idea.png See also Backup restoring.

More info about rdiff-backup:

Remote backup with rdiff-backup

#!/bin/bash
#
## BEGIN CONFIG ##
HOST=$(uname -n)
FILES="/home/openkm"
BACKUP_DIR="/mnt/backup"
## END CONFIG ##
echo -e "### BEGIN: $(date +"%x %X") ###\n"

# Stop JBoss
/etc/init.d/jboss stop

# Backup and purge old backups
rdiff-backup --remove-older-than 30B backup@server::$BACKUP_DIR/$HOST
rdiff-backup -v 3 --print-statistics --include $FILES --exclude '**' / backup@server::$BACKUP_DIR/$HOST

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

# Status
echo "=================================";
rdiff-backup --list-increment-sizes backup@server::$BACKUP_DIR/$HOST
echo "=================================";

Local backup to USB disk with rdiff-backup

USB disk mount point can be defined in /etc/fstab as:

 /dev/sdb1       /mnt/backup     ext4    defaults        0       0
#!/bin/bash
#
## BEGIN CONFIG ##
HOST=$(uname -n)
MYSQL_PASS=""
OPENKM_DB="okmdb"
OPENKM_HOME="/home/openkm"
TOMCAT_HOME="$OPENKM_HOME/tomcat-7.0.27"
DATABASE_EXP="$OPENKM_HOME/db"
BACKUP_DIR="/mnt/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

# Mount disk
if mount | grep "$BACKUP_DIR type" > /dev/null; then
  echo "$BACKUP_DIR already mounted";
else
  mount "$BACKUP_DIR";
fi

# 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 > $DATABASE_EXP/mysql_$OPENKM_DB.sql
  echo "-------------------------------------";
fi

# Backup and purge old backups
rdiff-backup --remove-older-than 30B $BACKUP_DIR/$HOST
rdiff-backup -v 3 --print-statistics --include $OPENKM_HOME --exclude '**' / $BACKUP_DIR/$HOST

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

# Status
echo "=================================";
rdiff-backup --list-increment-sizes $BACKUP_DIR/$HOST
echo "*********************************";
df -h | grep "$BACKUP_DIR"
echo "=================================";

# Umount disk
sync
umount "$BACKUP_DIR"

Remote backup to SMB or CIFS with rdiff-backup

If you are runing Ubuntu, install cifs-utils package.

#!/bin/bash
#
## BEGIN CONFIG ##
HOST=$(uname -n)
MYSQL_PASS=""
OPENKM_DB="okmdb"
OPENKM_HOME="/home/openkm"
TOMCAT_HOME="$OPENKM_HOME/tomcat-7.0.27"
DATABASE_EXP="$OPENKM_HOME/db"
BACKUP_DIR="/mnt/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

# Mount disk
if mount | grep "$BACKUP_DIR type" > /dev/null; then
  echo "$BACKUP_DIR already mounted";
else
  echo "Mounting $BACKUP_DIR ...";
  mount -t cifs //REMOTE_SERVER/REMOTE_DIR $BACKUP_DIR -o username=REMOTE_USER,password=REMOTE_PASSWORD,iocharset=utf8,file_mode=0777,dir_mode=0777
fi

# 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 > $DATABASE_EXP/mysql_$OPENKM_DB.sql
  echo "-------------------------------------";
fi

# Backup and purge old backups
rdiff-backup --remove-older-than 30B $BACKUP_DIR/$HOST
rdiff-backup -v 3 --print-statistics --include $OPENKM_HOME --exclude '**' / $BACKUP_DIR/$HOST

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

# Status
echo "=================================";
rdiff-backup --list-increment-sizes $BACKUP_DIR/$HOST
echo "*********************************";
df -h | grep "$BACKUP_DIR"
echo "=================================";

# Umount disk
sync
umount "$BACKUP_DIR"

Remote backup with rdiff-backup (JBoss)

#!/bin/bash
#
# @weekly /root/backup.sh
#
## BEGIN CONFIG ##
HOST=$(uname -n)
MYSQL_PASS=""
OPENKM_DB="okmdb"
OPENKM_HOME="/home/openkm"
TOMCAT_HOME="$OPENKM_HOME/tomcat-7.0.27"
DATABASE_EXP="$OPENKM_HOME/db"
BACKUP_DST="user@server::/path/to/backup/$HOST"
## END CONFIG ##

echo -e "### BEGIN: $(date +"%x %X") ###\n"
rm -rf $DATABASE_EXP
mkdir -p $DATABASE_EXP
 
# Stop JBoss
/etc/init.d/jboss stop

# Clean logs
echo "Clean JBoss temporal files."
# rm -rf $JBOSS_HOME/server/default/log
rm -rf $JBOSS_HOME/server/default/tmp
rm -rf $JBOSS_HOME/server/default/work
rm -rf $JBOSS_HOME/server/default/data/wsdl

# 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 > $DATABASE_EXP/mysql_$OPENKM_DB.sql
  echo "-------------------------------------";
fi

# Backup and purge old backups
rdiff-backup --remove-older-than 30B $BACKUP_DST
rdiff-backup -v 3 --print-statistics --include $OPENKM_HOME --exclude '**' / $BACKUP_DST

# Start JBoss
/etc/init.d/jboss start
echo -e "\n### END: $(date +"%x %X") ###"
 
# Status
echo "=================================";
rdiff-backup --list-increment-sizes $BACKUP_DST
echo "=================================";

Remote backup with rdiff-backup (Tomcat - MySQL)

#!/bin/bash
#
# @weekly /root/backup.sh
#
## BEGIN CONFIG ##
HOST=$(uname -n)
MYSQL_PASS=""
OPENKM_DB="okmdb"
OPENKM_HOME="/home/openkm"
TOMCAT_HOME="$OPENKM_HOME/tomcat-7.0.27"
DATABASE_EXP="$OPENKM_HOME/db"
BACKUP_DST="user@server::/path/to/backup/$HOST"
## END CONFIG ##

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 > $DATABASE_EXP/mysql_$OPENKM_DB.sql
  echo "-------------------------------------";
fi
 
# Backup and purge old backups
rdiff-backup --remove-older-than 30B $BACKUP_DST
rdiff-backup -v 3 --print-statistics --include $OPENKM_HOME --exclude '**' / $BACKUP_DST
 
# Start Tomcat
/etc/init.d/tomcat start
echo -e "\n### END: $(date +"%x %X") ###"
 
# Status
echo "=================================";
rdiff-backup --list-increment-sizes $BACKUP_DST
echo "=================================";

Remote backup with rdiff-backup (Tomcat - PostgreSQL)

#!/bin/bash
#
# @weekly /root/backup.sh
#
## BEGIN CONFIG ##
HOST=$(uname -n)
OPENKM_DB="okmdb"
OPENKM_HOME="/home/openkm"
TOMCAT_HOME="$OPENKM_HOME/tomcat-7.0.27"
DATABASE_EXP="$OPENKM_HOME/db"
BACKUP_DST="user@server::/path/to/backup/$HOST"
## END CONFIG ##

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 PostgreSQL
echo "* Backuping PostgreSQL data from $OPENKM_DB..."
su postgres -c "pg_dump $OPENKM_DB" > $DATABASE_EXP/pg_$OPENKM_DB.sql

# Databases optimizations
su postgres -c "vacuumdb -a -z" > /dev/null
su postgres -c "reindexdb -a -q" 2> /dev/null

echo "-------------------------------------"
 
# Backup and purge old backups
rdiff-backup --remove-older-than 30B $BACKUP_DST
rdiff-backup -v 3 --print-statistics --include $OPENKM_HOME --exclude '**' / $BACKUP_DST
 
# Start Tomcat
/etc/init.d/tomcat start
echo -e "\n### END: $(date +"%x %X") ###"
 
# Status
echo "=================================";
rdiff-backup --list-increment-sizes $BACKUP_DST
echo "=================================";