Automatic backup of Linux/Unix server data

Time:2022-9-21 documentation
Version: 2.0.1
Tool download address:
0. Version update
* 2006-11-23 v2.0.2
– [fix] Fix resin path
* 2005-03-28 v2.0.1
– [fix] Backup resin and tomcat configuration
– [fix] Fix config backup subdirectory location
1 Overview
The script can be used to back up data.
2. Install
tar zxf primabackup.tar.gz
3. Configuration
required settings
3.1 Backup to that directory
BACKUP_BASE_DIR="/backup" The root directory where the backup files are located
3.2 What data is backed up
WEB=1 backup web
EMAIL=1 backup email
DNS=1 backup dns
MYSQL=1 backup mysql
CONTROL=1 Backup the main control interface directory
If a feature does not need to be backed up, change it to 0
3.3 How many old backups are kept?
That is, in addition to the current latest backup, several backups are kept, the minimum is 0, and the default is 1.
If set to 0, only one backup will be kept, and the previous backup will be deleted each time it is backed up
4. Backup process
First according toset up, decide what data and configuration to back up, and then create
Backup the directory named date and time in the root directory, and back up the tar package of data in the data subdirectory of this directory
Backup configuration files and directories in the conf subdirectory.
5. Data Location
The location of the web data, the default /www/users, the program will automatically go to prima.conf to find the home_base configuration, if found, use the changed configuration
The location of the mail data, the default is /var/vmail, the program will automatically look for the mail_space_base configuration in prima.conf, if found, use the changed configuration
The location of dns data, the default is /var/named, the program will automatically go to prima.conf to find the zonefile_base configuration, if found, use the changed configuration
The location of mysql data, Linux defaults to /var/lib/mysql, FreeBSD defaults to /var/db/mysql
If website generation and counter applications are turned on in prima.conf, the corresponding data directory will be backed up.
The program determines whether to back up the corresponding resin and tomcat configurations according to use_mod_caucho/use_mod_jk in prima.conf
named.conf defaults to /etc/named.conf, the program will automatically look for the named_conf configuration in prima.conf, and if found, use the changed configuration
If the masterServeserver, be sure to turn on MYSQL backup.
6. About Test Mode
if the
change to
Otherwise, just print what is to be done, not do the actual backup.
7. Naming of backup filesmethod
For catalog backups. The backup file is the directory name .tar.gz, such as
/www/users -> /backup/20040903-140101/data/users.tar.gz
For file backup, it is directly the file name, such as
/etc/named.conf -> /backup/20040903-140101/conf/named.conf
The full list is as follows:
/www/prima -> data/prima.tar.gz
/www/users -> data/users.tar.gz
/var/vmail -> data/vmail.tar.gz
/var/named -> data/named.tar.gz
/var/lib/mysql -> data/mysql.tar.gz
/www/prima/htdocs/apps/GenComSite/sitepage -> data/sitepage
/www/prima/htdocs/apps/GenComSite/upload -> data/upload.tar.gz
/var/Counter -> Counter.tar.gz
/usr/prima/etc -> conf/etc.tar.gz
/usr/prima/postfix/conf -> conf/conf.tar.gz
/etc/named.conf -> conf/named.conf
/usr/local/resin/conf/host.conf -> conf/host.conf
/var/tomcat4/conf/server.xml -> conf/server.xml
/www/prima/htdocs/apps/phpMyAdmin/ -> conf/
8. Precautions
Note: This backup is a full backup and there should be enough space in the backup directory.
Although the space will be reduced after compression during the backup process, it is recommended that the backup directory be at least the same size as the entire data.
This ensures that at least one full backup can be accommodated, and in general, two full backups can be accommodated.
When backing up, the burden on the CPU and disk is relatively heavy. It is recommended to add nice to reduce the priority of program execution, and it is best to run it in the early morning.
# nice ./
9. Automatic periodic backup via cronjob
By modifying /etc/crontab, backups can be set to be periodic and automatic.
Each entry in /etc/crontab is a periodic task, except those beginning with #.
The format is as follows:
minutes hour day of month month day of the week executor command line
0 2 * * * root /bin/cmd
That is, execute the /bin/cmd command as root at 2 am every day
If you want to configure the backup task to be executed at 2 o'clock every day and write the output message to the log file, add the following to /etc/crontab:
0 2 * * * root nice /root/primabackup/ >> /var/log/primabackup.log
The above assumes that the location of the backup script is at /root/primabackup/
The log is placed in /var/log/primabackup.log
Added nice to lower the execution priority.
If you want to execute every Saturday at 2:00, then:
0 2 * * 6 root nice /root/primabackup/ >> /var/log/primabackup.log
(6 for Saturday, 0 or 7 for Sunday)
Modify /etc/crontab without restarting anythingServe