← All posts

FreeBSD. Backing Up Data with fsbackup

safe
After the rm -rf / incident, I finally got concerned about daily data backups. At first I planned to write my own little shell script, but then I decided to look for a ready-made solution…

Goal

  • Back up project files
  • Create database dumps for the projects (MySQL)
  • Upload the dumps to a remote FTP server

Tools

I chose fsbackup as the backup tool because it met our goals.

The fsbackup system was created to back up servers of various sizes to a dedicated backup server.

Installation

cd /usr/ports/sysutils/fsbackup
make install

More details on working with Ports and Packages in FreeBSD, as well as on updating the ports tree and installed packages.

Configuration

cd /usr/local/fsbackup

Create a directory for the archives

mkdir ./archive

Let’s make a backup copy and edit the configuration file

cp cfg_example server_backup.conf
vi server_backup.conf

It’s all straightforward, and in Russian, too :)
Now specify the configuration file to use in create_backup.sh

config_files="server_backup.conf"

FTP Settings

The server_backup.conf file

# Тип хранилища
$cfg_type = "remote_ftp";

# Сервер на который будет копироваться бэкап.
$cfg_remote_host = "server.remote.ru:21";

# Логин под которым будет сохранятся бэкап.
$cfg_remote_login = "backup_login";

# Директория куда должны помещаться файлы бэкапа, директория должна присутствовать.
$cfg_remote_path = "/home/backup_login/backup";

# пароль для входа по ftp.
$cfg_remote_password = "backup_password";

Specifying Directories and Files to Back Up

Find $cfg_root_path and specify the root directory relative to which the paths for placing files are defined (see __DATA__).

$cfg_root_path = "/";

Specify the directories and files to back up (the __DATA__ directive)

__DATA__

# Fsbackup
/usr/local/fsbackup
!/usr/local/fsbackup/cache
f!.core$
f!^core$
f!.o$
f!.log$

# BSD
/var/db/pkg
/usr/src/sys/i386/conf

# Users and PROJECT's
/home
/root
!/home/ftp
=!.netscape/cache/
=!.mozilla/.*/Cache/
=!.mozilla/.*/NewCache/
=!.mozilla/.*/News/
f!.*.avi$
f!.*.mpeg$
f!.*.mpg$
f!.*.mp3$

# System configuration
/etc
/var/cron/tabs
/var/spool/cron
/usr/local/etc

MySQL Backup

To back up MySQL, you need to edit ./scripts/mysql_backup.sh

Specify the username, password, and which databases we want to dump.

You also need to edit the startup file ./create_backup.sh and specify that we need a MySQL backup!


backup_mysql=1

Next, Add a Cron Entry

crontab -e
0 4 * * * /usr/local/fsbackup/create_backup.sh| mail -s"`uname -n` backup report" root

A brief cron reference and a cheat sheet.

Security!

For backup encryption, see http://www.opennet.ru/dev/fsbackup/#shi

Restoring Data

The ./scripts/fsrestore.sh script can be used to fully restore data from an incremental backup. To restore, simply edit the paths inside the script and run it.

Comments are closed. Read the original discussion in Russian →