📄 mmm_backup
字号:
#!/usr/bin/env perl# Use mandatory external modulesuse strict;use Cwd;use File::Basename;use Data::Dumper;use POSIX;use Config;use Getopt::Long;# Determine installation dir nameour $SELF_DIR = dirname(dirname(Cwd::abs_path(__FILE__)));# Include parts of the systemrequire $SELF_DIR . '/lib/config.pm';require $SELF_DIR . '/lib/log.pm';require $SELF_DIR . '/lib/db.pm';#-----------------------------------------------------------------#Parse optionsmy $config_file = "mmm_lvm.conf";my $host_name;my $copy_method;my $dest_dir;GetOptions("config=s" => \$config_file, "host=s" => \$host_name, "copy-method=s" => \$copy_method, "dest-dir=s" => \$dest_dir);#-----------------------------------------------------------------# Read config fileour $config = ReadConfig($config_file);$copy_method = $config->{default_copy_method} unless ($copy_method);print "Copy method: '$copy_method'\n\n";# Parse clone dirsmy @clone_dirs : shared = split(/\,/, $config->{clone_dirs});$config->{clone_dirs} = \@clone_dirs;# Check host namemy $clone_host = $config->{host}->{$host_name};PrintUsage("Invalid host name!") unless ($clone_host);# Check copy methodmy $method = $config->{copy_method}->{$copy_method};PrintUsage("Invalid copy method ($copy_method)!") unless ($method);# Check copy methodmy $should_be_empty = ($method->{incremental} ne 'yes');PrintUsage("Invalid destination directory!") unless (CheckDestDir($dest_dir, $should_be_empty));# Print infoLogNotice("Host: '$host_name'");LogNotice("Copy method: '$copy_method'");LogNotice("Dirs to backup: '" . join(', ', @clone_dirs) . "'");#-----------------------------------------------------------------# Create config shortcutsmy $this = $config->{this};my $host = $config->{host}->{$this};LogNotice("-----------------------------------------------------------------");# Executing copying processmy $res = system("$SELF_DIR/sbin/mmm_get_dump --config $config_file --host $host_name --copy-method $copy_method --dest-dir $dest_dir");if ($res) { LogError("Error: Can't copy data from remote server"); exit(1);}LogNotice("-----------------------------------------------------------------");LogNotice("Backup process done!\n\n\n");exit(0);#-----------------------------------------------------------------sub PrintUsage($) { my $error = shift; print "ERROR: $error\n\n"; print "Usage: $0 [--config <config file>] --host <host> --dest-dir <dir> [--copy-method <copy_method>]\n"; print "Where:\n"; print " Host = " . join('|', keys(%{$config->{host}})) . "\n"; print " Copy method = " . join('|', keys(%{$config->{copy_method}})) . " (default = $config->{default_copy_method})\n\n"; exit(1);}#-----------------------------------------------------------------sub CheckDestDir($$) { my $dir = shift; my $should_be_empty = shift; return 0 unless ($dir); mkdir($dir) unless (-e $dir); return 0 if (-f $dir); return 0 unless (-r $dir && -x $dir && -w $dir); return 0 if ($should_be_empty && scalar(glob("$dir/*"))); return 1;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -