Good day
% habrauser% !
As you know backup - must be! But just to make an archive of data - this does not mean a competent backup. When
Calculate directory server- based servers started appearing at our clients, the question arose of choosing the means for creating backup copies of data. The search for ready-made solutions did not give anything sensible, so I had to write it myself.
To begin, I will say that we first need from the program:
- Incremental archives
- Confidence in the availability of archives
- Customization flexibility
- Work report
Clause 1 has special requirements. Not all archivers are able to do increments from an already incremental archive, and this is precisely what we need.
The program is written in bash. I will not give the text of the script here for it is large enough. I'd better comment on the default config, so, in my opinion, the features of the program will be seen better.
')
The configuration file contains parameter blocks: one mandatory “main” and additional ones. The required block has a strictly defined name “main” and describes the main archiving parameters, here you can also set common archiving parameters that will be used for all additional blocks. Additional blocks may have arbitrary names. They describe the parameters of specific archives. The order of the block description does not matter, the main thing is to specify which block will be processed next.
The configuration given below describes the following archiving logic:
- The first day of each month to do a full data archive (monthly archive). It will be placed in the folder "/ backup / ARCH / Monthly /" with the name "fullsystem.tar". If successful, the old archives older than 3 months will be deleted.
- Every Sunday to do an incremental archive from the monthly (weekly archive). It will be placed in the folder "/ backup / ARCH / Weekly /" with the same name. If successful, the old archives older than 4 weeks will be deleted.
- Every day to do an incremental archive from the weekly (daily archive). It will be placed in the folder "/ backup / ARCH / Dayly /" with the same name. Upon successful completion, old archives older than 8 days will be deleted.
- The list of files to be archived is specified in the file “monthly.include”, the files that should be excluded are specified in “monthly.exclude”
$ cat /etc/defconf/main.conf
#
# ,
# . (m)
main {
#
# .
DEF_ARCHIVE_PATH="/backup/ARCH"
#
ARCHIVE_PATH=$DEF_ARCHIVE_PATH
#
ARCHIVE_NAME="fullsystem.tar"
#
REMOVE_DEPTH=3
# tar (m)
TAR_ADD_PARAMS="-vR"
#
# ( ) (m)
TAR_ERR_EXCLUDE="0 "
# ( "/etc/ssmtp/ssmtp.conf",
# "mutt")
#
SUBJECT="ITEq Error level: $ERROR_CODE"
#
MAILTO="logger@site.ru"
# (all - , error - ,
# )
SENDMAIL='all'
#
NEXT=montly
}
#
#
#
#
montly {
ARCHIVE_PATH="$DEF_ARCHIVE_PATH/Monthly/"
#
# 1 12; 0 - ( 1-12 0/1)
# (1-3)
# (0/3).
MONTH=0
#MONTH=1-12
#MONTH=0/1
#
# 1 31
#
DAY=1
#
# 1 7 (1 - )
#
DAY_OF_WEEK=0
#
TO_ARCHIVE_FILE_LIST="monthly.include"
#
EXCLUDE_FROM_ARCHIVE="monthly.exclude"
#
REMOVE_DEPTH=3
#
NEXT=weekly
}
#
weekly {
ARCHIVE_PATH="$DEF_ARCHIVE_PATH/Weekly/"
MONTH=0
DAY=0
DAY_OF_WEEK=7
TO_ARCHIVE_FILE_LIST="monthly.include"
EXCLUDE_FROM_ARCHIVE="monthly.exclude"
REMOVE_DEPTH=4
NEXT=dayly
}
#
dayly {
ARCHIVE_PATH="$DEF_ARCHIVE_PATH/Dayly/"
MONTH=0/1
DAY=0
DAY_OF_WEEK=0
TO_ARCHIVE_FILE_LIST="monthly.include"
EXCLUDE_FROM_ARCHIVE="monthly.exclude"
REMOVE_DEPTH=8
NEXT=none
}
To set the objects to be archived, as well as those excluded from it, regular files are used that are accepted by tar. These two files should be located in the folder with the config. Also in the folder with the config is the folder "services". In this folder, you can throw links to services that will stop immediately before archiving, and then run again. You can also throw executable files there, in which you can describe additional actions before and after archiving. All these files are started with the “stop” parameter before archiving and “start” after archiving.
To install, download the
bbackup.tar archive and unpack it where it is not a pity, and run “setup.sh”.
The very start of the program to the disgrace is simple:
bbackup.sh <config file>
For example:
$ bbackup.sh /etc/defconf/main.conf
But the script was created for automation, so we stuff it into crowns for daily execution.
echo -e "#!/bin/sh\n/sbin/bbackup.sh /etc/bbackup/defconf/main.conf">/etc/cron.daily/bbackup.sh
On this, perhaps I finish. All successful backups and let them never be useful to you!
PS Immediately I bring my apologies for some confusion and unstructuredness of this post. I have long wanted to write it, but still my hands did not reach, therefore it was written in a fit of enthusiasm to the detriment of sleep%)