Backups - andyceo/documentation GitHub Wiki
На этой странице описываются различные подходы к бекапам.
- Скрипт: https://github.com/andyceo/bash_scripts/blob/master/darbackup.sh
- Пример конфигурации задания: https://github.com/andyceo/bash_scripts/blob/master/darbackup_sample_task.dcf
Список страниц, которые вдохновили на написание:
- http://evil.org.ua/rezervnoe-kopirovaniya-s-pomoshhyu-util/
- http://gradha.sdf-eu.org/textos/dar-differential-backup-mini-howto.en.html
- http://openlife.cc/blogs/2011/july/backup-scripts-fro-dar
- http://www.g-loaded.eu/2007/12/01/veritar-verify-checksums-of-files-within-a-tar-archive/ (tar with files checksums)
- http://www.halfgaar.net/backing-up-unix (backing up unix)
- http://habrahabr.ru/blogs/sysadm/136313/
- http://habrahabr.ru/blogs/linux/87435/
- http://habrahabr.ru/blogs/linux/136595/
- http://habrahabr.ru/blogs/backup/133330/
- http://habrahabr.ru/blogs/linux/41492/
- http://habrahabr.ru/blogs/sysadm/97685/ (простой скрипт для инкрементального бекапа директорий)
- http://habrahabr.ru/blogs/sysadm/111555/ (bacula amazon s3)
- http://habrahabr.ru/blogs/sysadm/86526/ (bacula)
- http://habrahabr.ru/blogs/sysadm/135291/ (bacula)
Скрипты для примера:
```bash
#!/bin/sh
BACKUP_DIR="/home/backup"
DIRECTORY_LIST="/usr/local/etc/scripts/backup-list/dir.list"
LOGFILE="/var/log/backup.log"
LOG_DATE=`/bin/date "+%H:%M:%S %d.%m.%Y"`
DATE=`/bin/date "+%Y-%m-%d"`
SED="/usr/bin/sed"
dar="/usr/local/bin/dar"
case $1 in
full)
rm ${BACKUP_DIR}/*.dar 2>&1 >/dev/null
for BACKUP in `cat ${DIRECTORY_LIST}`
do
BACKUP_ARK=`echo ${BACKUP} | sed 's/\// /g' | awk '{ print $2 ; }'`
if ${dar} -m 1024 -y9 -D -R ${BACKUP} -c ${BACKUP_DIR}/${BACKUP_ARK}-${DATE} > /dev/null ;
then
if ${dar} -t ${BACKUP_DIR}/${BACKUP_ARK}-${DATE} > /dev/null ;
then
echo "${LOG_DATE} | Backup ${BACKUP_ARK}-${DATE} is successfully created and tested." >> ${LOGFILE}
else
echo "${LOG_DATE} | Backup ${BACKUP_ARK}-${DATE} is successfully created, validation failed." >> ${LOGFILE}
fi
else
echo "${LOG_DATE} | During backup ${BACKUP_ARK}-${DATE} the error occurred." >> ${LOGFILE}
fi
done
;;
differential)
for BACKUP in `cat ${DIRECTORY_LIST}`
do
BACKUP_ARK=`echo ${BACKUP} | sed 's/\// /g' | awk '{ print $2 ; }'`
PREV_BACKUP=`/bin/ls -rU ${BACKUP_DIR}/${BACKUP_ARK}-*.dar | /usr/bin/tail -n 1`
if ${dar} -m 1024 -y9 -D -R ${BACKUP} -c ${BACKUP_DIR}/${BACKUP_ARK}-${DATE}-diff -A ${PREV_BACKUP%%.*} > /dev/null ;
then
if ${dar} -t ${BACKUP_DIR}/${BACKUP_ARK}-${DATE}-diff > /dev/null ;
then
echo "${LOG_DATE} | Backup ${BACKUP_ARK}-${DATE}-diff is successfully created and tested." >> ${LOGFILE}
else
echo "${LOG_DATE} | Backup ${BACKUP_ARK}-${DATE}-diff is successfully created, validation failed." >> ${LOGFILE}
fi
else
echo "${LOG_DATE} | During backup ${BACKUP_ARK}-${DATE}-diff the error occurred." >> ${LOGFILE}
fi
done
;;
check)
for BACKUP in `cat ${DIRECTORY_LIST}`
do
BACKUP_ARK=`echo ${BACKUP} | sed 's/\// /g' | awk '{ print $2 ; }'`
CHECK_BACKUP=`/bin/ls -rU ${BACKUP_DIR}/${BACKUP_ARK}*.dar | /usr/bin/tail -n 1 | cut -d . -f 1,1`
${dar} -t ${CHECK_BACKUP}
done
;;
esac
```
```bash
#!/bin/bash
# Script Name: dar_backups.sh
# Author: Roi Rodriguez Mendez & Mauro Silvosa Rivera (Cluster Digital S.L.)
# Description: dar_backups.sh is a script to be runned from cron which
# backups data and stores it locally and optionally remote using scp.
# It decides between doing a master or an incremental backup based
# on the existance or not of a master one for the actual month.
# Version: 1.0
# Revision History:
# 22.08.2005 - Creation
# Base directory where backups are stored
BASE_BAK_DIR=/var/BACKUP/data
# Directory where backups for the actual month are stored (path relative to
# $BASE_BAK_DIR)
MONTHLY_BAK_DIR=`date -I | awk -F "-" '{ print $1"-"$2 }'`
# Variable de comprobacion de fecha
CURRENT_MONTH=$MONTHLY_BAK_DIR
# Name and path for the backup file.
SLICE_NAME=${BASE_BAK_DIR}/${MONTHLY_BAK_DIR}/backup_`date -I`
# Max backup file size
SLICE_SIZE=100M
# Remote backup settings
REMOTE_BAK="true"
REMOTE_HOST="example.com"
REMOTE_USR="bakusr"
REMOTE_BASE_DIR="/var/BACKUP/example.com/data"
REMOTE_MONTHLY_DIR=$MONTHLY_BAK_DIR
REMOTE_DIR=${REMOTE_BASE_DIR}/${REMOTE_MONTHLY_DIR}
## FUNCTIONS' DEFINITION
# Function which creates a master backup. It gets "true" as a parameter
# if the monthly directory has to be created.
function master_bak () {
if [ "$1" == "true" ]
then
mkdir -p ${BASE_BAK_DIR}/${MONTHLY_BAK_DIR}
fi
/usr/bin/dar -m 256 -s $SLICE_SIZE -y -R / \
-g ./DATA -g ./home -g ./root -c ${SLICE_NAME}_master > /dev/null
if [ "$REMOTE_BAK" == "true" ]
then
/usr/bin/ssh ${REMOTE_USR}@${REMOTE_HOST} "if [ ! -d ${REMOTE_DIR} ]; then mkdir -p $REMOTE_DIR; fi"
for i in `ls ${SLICE_NAME}_master*.dar`
do
/usr/bin/scp -C -p $i ${REMOTE_USR}@${REMOTE_HOST}:${REMOTE_DIR}/`basename $i` > /dev/null
done
fi
}
# Makes the incremental backups
function diff_bak () {
MASTER=$1
/usr/bin/dar -m 256 -s $SLICE_SIZE -y -R / \
-g ./DATA -g ./home -g ./root -c ${SLICE_NAME}_diff \
-A $MASTER > /dev/null
if [ "$REMOTE_BAK" == "true" ]
then
for i in `ls ${SLICE_NAME}_diff*.dar`
do
/usr/bin/scp -C -p $i ${REMOTE_USR}@${REMOTE_HOST}:${REMOTE_DIR}/`basename $i` > /dev/null
done
fi
}
## MAIN FLUX
# Set appropriate umask value
umask 027
# Check for existing monthly backups directory
if [ ! -d ${BASE_BAK_DIR}/${MONTHLY_BAK_DIR} ]
then
# If not, tell master_bak() to mkdir it
master_bak "true"
else
# Else:
# MASTER not void if a master backup exists
MASTER=`ls ${BASE_BAK_DIR}/${MONTHLY_BAK_DIR}/*_master*.dar | tail -n 1 | awk -F "." '{ print $1 }'`
# Check if a master backup already exists.
if [ "${MASTER}" != "" ]
then
# If it exists, it's needed to make a differential one
diff_bak $MASTER
else
# Else, do the master backup
master_bak "false"
fi
fi
```
- rsync
- http://zenon.sytes.net/rotation-backup/ (rsync)
- http://habrahabr.ru/blogs/linux/51419/ (rsync)
- Backup в Linux: настраиваем rsync-сервер
- Backup в Linux: rsync-клиент
- Backup в Linux: пишем скрипт (rsync)
Ссылки:
- Rsnapshot — инкрементальное резервное копирование и все другие страницы про rsnapshot
- Network Backups via Rsync and Rsnapshot
- Rsnapshot (Rsync Based) – A Local/Remote File System Backup Utility for Linux
- How to Install and Use Rsnapshot (Making Server's Backups)
Тестировать конфигурацию:
sudo rsnapshot configtest
Посмотреть занятое бекапами место:
sudo rsnapshot du
Посмотреть логи создания бекапа:
sudo tail -f /var/log/rsnapshot.log
Посмотреть разницу между двумя созданными бекапами, с выводом чисел в человеколюбивом формате и списком изменившихся файлов:
sudo rsnapshot-diff -H -v /rsnapshot/alpha.0 /rsnapshot/alpha.1
Посмотреть разницу с помощью rsync
(учитывает жесткие ссылки на файлы, но не показывает занятое место в случае наличия различий):
sudo rsync -aHin dir2/ dir1 2>&1 | grep -v '^\.d'
Установка:
```bash
sudo aptitude install backup-manager
```
Ссылки:
- Краткая инструкция
- Хороший мануал по backup-manager практически на все случаи жизни: Home office backup (abadr)