LQPP/lf-backup.sh

Aus Piratenwiki
Wechseln zu: Navigation, Suche
#!/bin/sh

LOGFILE="/var/log/liquid_feedback/lf-backup.log" 

TIMESTAMP=$( date '+%R_%F' )
FILENAME="/var/lib/liquid_feedback/backup/lqpp_${TIMESTAMP}"

REMOTE="lqpp-backup@localhost:~"
RECIPIENT="lqpp-backup"

# log to console, logfile and syslog
log () {
  echo "$1"
  echo "${TIMESTAMP}: $1" | tee -a "${LOGFILE}" | logger -t "lf-backup"
}

# print error message and quit
die () {
  log "ERROR: $1"
  exit 1
}

log "Start lf-backup..." 

echo "Dump..."
MSG=$( sudo -u postgres pg_dump --disable-triggers --data-only --column-inserts  liquid_feedback_pp > "${FILENAME}.sql" 2>&1 )
[ $? -ne 0 ] && die "Could not create database dump: ${MSG}"

echo "Pack..."
MSG=$( tar -cjf "${FILENAME}.tar.bz2" "${FILENAME}.sql" "/opt/liquid_feedback" "/var/www" "/etc" 2>&1 )
[ $? -eq 0 ] || die "Could not pack backup: ${MSG}"

echo "Encrypt..."
MSG=$( gpg --encrypt --recipient "${RECIPIENT}" "${FILENAME}.tar.bz2" 2>&1 )
[ $? -eq 0 ] || die "Could not encrypt backup: ${MSG}"

echo "Send..."
MSG=$( scp "${FILENAME}.tar.bz2.gpg" "${REMOTE}" 2>&1 )
[ $? -eq 0 ] || die "Could not send backup: ${MSG}"