backup_dailyMay 12, 2020

Daily Backup of Server Files

Introduction

The backup_daily scripts are intended to backup other servers to the local server. It uses the rsync program to backup the server files.

The scripts also scan the files for viruses with clamav.

The scripts saves backup reports for a week. They keep a history of the backup sizes for each server which are useful for trend analysis and capacity planning.

Download

A compressed tar file containing the backup_daily scripts and its working directories can be downloaded here: backup_daily.tgz

Organization

The backup script uses a directory organization as follows:

backup_daily
├── bin
│   ├── backup
│   ├── check-ssh
│   ├── cron-backup.sh
│   ├── cron-scan.sh
│   ├── cron.sh
│   ├── scan
│   └── ssh-sendkey
├── config
│   ├── SERVERS_TO_BACKUP
│   ├── SERVERS_TO_SCAN
│   └── STANDARD_OPTIONS
├── config.sample
│   ├── backupbox
│   ├── console
│   ├── git
│   ├── ldap
│   ├── mx
│   ├── ns1
│   ├── portal
│   ├── public
│   ├── SERVERS_TO_BACKUP
│   ├── SERVERS_TO_SCAN
│   ├── STANDARD_OPTIONS
│   ├── vmail
│   ├── web
│   └── workgroups
├── reports
│   ├── BACKUP_REPORT -> BACKUP_REPORT.Mon
│   ├── BACKUP_REPORT.Fri
│   ├── BACKUP_REPORT.Mon
│   ├── BACKUP_REPORT.Sat
│   ├── BACKUP_REPORT.Sun
│   ├── BACKUP_REPORT.Thu
│   ├── BACKUP_REPORT.Tue
│   ├── BACKUP_REPORT.Wed
│   ├── du.log
│   ├── SCAN_REPORT -> SCAN_REPORT.Mon
│   ├── SCAN_REPORT.Fri
│   ├── SCAN_REPORT.Mon
│   ├── SCAN_REPORT.Sat
│   ├── SCAN_REPORT.Sun
│   ├── SCAN_REPORT.Thu
│   ├── SCAN_REPORT.Tue
│   └── SCAN_REPORT.Wed
└── servers
    ├── current-rotation -> rotation-1
    ├── rotation-1
    └── rotation-2

The bin directory holds the backup script and it's companion scripts. The config directory holds the configuration settings determining which servers get backed up and the rsync options to use. Optional configuration files for individual servers contain additional rsync options to apply for just that server.

The servers directory holds the server backup files. Multiple rotations of backups can be made limited only by the amount of storage you have.

The reports directory holds the backup reports for a week. The du.log contains the sizes of each server after each backup. It allows the daily report to have a week's summary of server sizes and the amount of space they increased or decreased.

The following is an example of the backup reports that gets emailed to the administrator every day.

Example backup report

Invocation

The backup script is intended to be run automatically by cron. An example entry is:

# Daily Backups
05 1    * * *   root    BACKUP_ROTATIONS=3 /backup/daily/bin/cron.sh

There are three cron scripts available. The cron.sh script performs the backups and if time allows scans the files for viruses with clamscan. There are also cron scripts for just doing the backup (cron-backup.sh) or just doing the virus scan (cron-scan.sh). Results are emailed to the root user.