In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how to use backupninja to customize backup plan in Debian system". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to use backupninja to customize backup plan in Debian system".
Review backupninja
A unique feature of backupninja is that it can completely discard the plain text configuration files and operation files in / etc/backup.d, and the software will take care of it. In addition, we can write custom scripts (also known as "handler") and put them in the / usr/share/backupninja directory to complete different types of backup operations. In addition, we can be guided to create some configuration files through ninjahelper's ncurses-based interactive menu (also known as "helper") to minimize human errors.
Create custom Handler and Helper
The goal of this section is to create a script that backs up the home directory as a gzip or bzip2 package, excluding music and video files. Let's name this file home and put it in the / usr/backup/ninja directory.
Although you can use the default tar handler (see / usr/share/backupninja/tar and / usr/share/backupninja/tar.helper) to achieve this effect, we use this approach to show how to create practical handler scripts and ncurses-based helper. You can decide how to use this method according to your needs.
Because handlers comes from the main script, there is no need for a shebang line that starts with #! / bin/bash.
The handler (/ usr/share/backupninja/home) we wrote is as follows. It's been annotated in detail. The getconf function reads the configuration file for the backup operation. If you specify the value of a variable, it overrides the value of the corresponding variable in the configuration file:
The code is as follows:
# / home directory handler script
# each backup file authenticates the host through FQDN
Getconf backupname
# the directory where backup files are saved
Getconf backupdir
# default compression
Getconf compress
# include / home directory
Getconf includes
# does not contain * .mp3 and * .mp4 files
Getconf excludes
# default extension of backup files to be packaged
Getconf EXTENSION
# absolute path of tar program
Getconf TAR `which tar`
# absolute path of date program
Getconf DATE `which date`
# date format
DATEFORMAT= "Y-%m-%d"
# if the backup directory does not exist, exit with a fatal error
If [!-d "$backupdir"]
Then
Mkdir-p "$backupdir" | | fatal "Can not make directory $backupdir"
Fi
# if the backup directory is not writable, also exit with a fatal error
If [!-w "$backupdir"]
Then
Fatal "Directory $backupdir is not writable"
Fi
# Select the corresponding tar option according to the compression format
Case $compress in
"gzip")
Compress_option= "- z"
EXTENSION= "tar.gz"
"bzip")
Compress_option= "- j"
EXTENSION= "tar.bz2"
"none")
Compress_option= ""
*)
Warning "Unknown compress filter ($tar_compress)"
Compress_option= ""
EXTENSION= "tar.gz"
Esac
# does not contain some file types / directories
Exclude_options= ""
For i in $excludes
Do
Exclude_options= "$exclude_options-- exclude $I"
Done
# Debug information, perform backup operation
Debug "Running backup:" $TAR-c-p-v $compress_option $exclude_options\
-f "$backupdir/$backupname-" `$DATE "+ $DATEFORMAT"` ". $EXTENSION"\
$includes
# redirect standard output to a file with a .list extension
# redirect standard error output to a file with .err extension
$TAR-c-p-v $compress_option $exclude_options\
-f "$backupdir/$backupname-" `$DATE "+ $DATEFORMAT"` ". $EXTENSION"\
$includes\
> "$backupdir/$backupname-" `$DATE "+ $DATEFORMAT"` .list\
2 > "$backupdir/$backupname-" `$DATE "+ $DATEFORMAT"`. Err
[$?-ne 0] & & fatal "Tar backup failed"
Next we will create the helper file (/ usr/share/backupninja/home.helper). In this way, the hendlers will be displayed in ninjahelper as a menu:
The code is as follows:
# backup operation description, dividing words with an underscore
HELPERS= "$HELPERS home:backup_of_home_directories"
Home_wizard () {
Home_title= "Home action wizard"
Backupname= `hostname-- fqdn`
# specify the time of backup operation
InputBox "$home_title"When to run this action?" "everyday at 01"
[$? = 1] & & return
Home_when_run= "when = $REPLY"
# specify backup file name
InputBox "$home_title"\ "Name\" of backups "$backupname"
[$? = 1] & & return
Home_backupname= "backupname= $REPLY"
Backupname= "$REPLY"
# specify the default path for saving backup files
InputBox "$home_title"Directory where to store the backups" / var/backups/home "
[$? = 1] & & return
Home_backupdir= "backupdir= $REPLY"
# specify the default value of the check box
RadioBox "$home_title"Compression"\
"none"No compression" off\
"gzip"Compress with gzip" on\
"bzip"Compress with bzip" off
[$? = 1] & & return
Result= "$REPLY"
Home_compress= "compress= $REPLY"
REPLY=
While [- z "$REPLY"]; do
FormBegin "$home_title: Includes"
FormItem "Include:" / home/gacanepa
FormDisplay
[$? = 0] | | return 1
Home_includes= "includes="
For i in $REPLY; do
[- n "$I"] & & home_includes= "$home_includes $I"
Done
Done
REPLY=
While [- z "$REPLY"]; do
FormBegin "$home_title: Excludes"
FormItem "Exclude:" * .mp3
FormItem "Exclude:" * .mp4
# add multiple "Exclude" text boxes as needed to specify other content that does not need to be included
FormItem "Exclude:"
FormItem "Exclude:"
FormDisplay
[$? = 0] | | return 1
Home_excludes= "excludes="
For i in $REPLY; do
[- n "$I"] & & home_excludes= "$home_excludes $I"
Done
Done
# Save configuration
Get_next_filename $configdirectory/10.home
Cat > $next_filename
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.