Table of Contents

File System Backup

NOTE: THIS HAS NOT BEEN FULLY TESTED!

Create a cron.daily job to backup a directory

Below is the script for backing up website directory.

Prerequisites

mkdir -p /data/backups/www

Script Updates

Features

File location: /etc/cron.daily/www_backup

www_backup
#!/bin/sh
#
# WWW backup script
#
NOW=$(date +"%Y-%m-%d-%H-%M-%S")
#
BACKUPLOC="/data/backups"
WWWBACKUPLOC="$BACKUPLOC/www"
BACKUPFILE="$WWWBACKUPLOC/backup-www-${NOW}.tar.gz"
LOGFILE="$WWWBACKUPLOC/backup-www-${NOW}.log"
FILE_DIR_PATH="/data/www"
#
# Backup Data
tar -zcvf ${BACKUPFILE} -C $FILE_DIR_PATH . > $LOGFILE
chmod 600 $BACKUPFILE
#
/usr/bin/find $WWWBACKUPLOC/backup-www*.tar.gz -mtime +7 -exec rm {} \;
/usr/bin/find $WWWBACKUPLOC/backup-www*.log -mtime +7 -exec rm {} \;
#
exit 0

Post Install

chmod 700 /etc/cron.daily/www_backup