我想在Cpanel
备份系统的.tar.gz
文件备份上设置密码
cpanel使用perl
脚本在/scripts/cpbackup
文件路径中进行备份
所以,我编辑这个文件并在这里找到这个函数:
sub backupaccts {
my $target = shift;
my $all_targets = shift;
Cpanel::FileUtils::TouchFile::touchfile($target);
#if another cpbackup starts just go bye bye
if ( !( $CONF{'BACKUPFILES'} eq "no" ) ) {
print "[cpbackup] Running dir & file backup with target : $target\n";
if ( !-e "$target/files" ) {
mkdir( "$target/files", 0700 );
}
if ( !-e "$target/dirs" ) {
mkdir( "$target/dirs", 0700 );
}
chmod( 0700, "$target/files", "$target/dirs" );
my ( $syncstatus, $syncmessage );
foreach my $file (@FILES) {
next if ( !-e $file );
my $rawfile = $file;
$rawfile =~ s/\//_/g;
if ( $CONF{'BACKUPINC'} eq "yes" ) {
( $syncstatus, $syncmessage ) = Cpanel::SimpleSync::syncfile( $file, "$target/files/$rawfile", 0, 1 );
}
else {
( $syncstatus, $syncmessage ) = Cpanel::SimpleSync::syncfile( $file, "$target/files/$rawfile", 0, 1 );
if ( $syncstatus != 0 ) {
if ( cpusystem( $gzip_bin, "-f", "$target/files/$rawfile" ) != 0 ) {
print STDERR "[cpbackup] Failed to compress file $target/files/$rawfile\n";
}
}
}
if ( $syncstatus == 0 ) { print STDERR "[cpbackup] Failed to backup $file ($syncmessage)\n"; }
}
foreach my $dir (@DIRS) {
next if ( !-e $dir );
my $rawdir = $dir;
$rawdir =~ s/\//_/g;
my @EXCLUDES = (
$dir eq '/var/cpanel'
? ( "--exclude=lastrun/*", "--exclude=bwusagecache/*", "--exclude=serviceauth/*", "--exclude=dnsrequests_db/*", "--exclude=configs.cache/*" )
: ("--exclude=*/proc/*")
);
# Added exclude for /proc for chroot bind setups to prevent error messages
if ( $CONF{'BACKUPINC'} eq "yes" ) {
if ( cpusystem( $rsync_bin, $rsyncopts, @EXCLUDES, '--delete', "$dir/", "$target/dirs/$rawdir" ) != 0 ) {
print STDERR "[cpbackup] Failed to perform incremental backup of $dir/ to $target/dirs/$rawdir\n";
}
}
else {
if ( cpusystem( $tar_bin, '--use-compress-program=/usr/local/cpanel/bin/gzip-wrapper', '--create', '--preserve-permissions', '--file', "$target/dirs/$rawdir.tar.gz", @EXCLUDES, $dir ) == 0 ) {
chmod( 0600, "$target/dirs/$rawdir.tar.gz" );
}
else {
print STDERR "[cpbackup] Failed to perform full backup of $dir/ to $target/dirs/$rawdir.tar.gz\n";
}
}
}
}
print "[cpbackup] Running account backup with target : $target\n";
#BACKUPLOGS no
#MYSQLBACKUP accounts
#BACKUPBWDATA yes
$ENV{'pkgacct-logs'} = ( $CONF{'BACKUPLOGS'} eq "yes" ? 'yes' : 'no' );
$ENV{'pkgacct-mysql'} = ( ( $CONF{'MYSQLBACKUP'} eq "dir" || $CONF{'MYSQLBACKUP'} eq "no" ) ? 'no' : 'yes' );
$ENV{'pkgacct-psql'} = ( $CONF{'PSQLBACKUP'} eq "no" ? 'no' : 'yes' );
$ENV{'pkgacct-bwdata'} = ( $CONF{'BACKUPBWDATA'} eq "no" ? 'no' : 'yes' );
my %user_error_map = ();
if ( $CONF{'BACKUPACCTS'} ne 'no' ) {
# we need to be sure that all accounts are converted to the new backup system
# user config need to have the LEGACY_BACKUP entry
# this can be missing when importing an account prior 11.36
# or if an error happen during the upgrade process
Install::LegacyBackups->new()->perform();
Cpanel::PwCache::init_passwdless_pwcache();
my @cpusers = Cpanel::Config::Users::getcpusers();
foreach my $user ( sort @cpusers ) {
my $user_conf = Cpanel::Config::LoadCpUserFile::load($user);
$user_conf->{'LEGACY_BACKUP'} = 0 if !exists $user_conf->{'LEGACY_BACKUP'};
next if !$user_conf->{'LEGACY_BACKUP'};
if ( $CONF{'BACKUPINC'} eq 'yes' ) {
my $last_update_time = time();
utime( $last_update_time, $last_update_time, "$target/$user" );
}
if ( cpusystem( $pkgacct, ( $CONF{'COMPRESSACCTS'} eq 'no' ? '--nocompress' : () ), ( $CONF{'BACKUPINC'} eq "yes" ? '--incremental' : () ), $user, $target, 'backup' ) != 0 ) {
print STDERR "[cpbackup] Failed to back up account $user\n";
$user_error_map{$user}{'account'} = {
'error_message' => ( $LAST_CPUSYSTEM_ERROR || 'Failed to backup account' ) # FIXME: This is a hack to avoid refactoring cpusystem
};
}
else {
if ( $CONF{'BACKUPTYPE'} eq 'ftp' ) {
my $target_file = ( $CONF{'COMPRESSACCTS'} eq 'no' ? "$user.tar" : "$user.tar.gz" );
foreach my $remote_target (@$all_targets) { # If we are going to update multiple targets we send the file multiple times
# previously we would build the backup once for every target. Now we just upload it once
# instead as we know all the targets before we get here now
my %ftp_error_info = ftpsend( $remote_target, $target . '/' . $target_file, $target_file );
$user_error_map{$user}{'transport'}{$remote_target} = \%ftp_error_info if keys %ftp_error_info;
}
unlink( $target . '/' . $target_file );
}
}
}
}
return \%user_error_map;
}
如您所见,此行正在为存档备份创建.tar.gz
文件:
cpusystem( $tar_bin, '--use-compress-program=/usr/local/cpanel/bin/gzip-wrapper', '--create', '--preserve-permissions', '--file', "$target/dirs/$rawdir.tar.gz", @EXCLUDES, $dir )
我知道如何使用zip
,gpg
,crypt
,...但我不知道如何在此功能中使用它并追加它。
你做这项工作的想法是什么?而且我不懂perl编程,所以如果可以,请为我提供示例代码。
答案 0 :(得分:0)
我知道如何使用zip,gpg,crypt,......但是我不知道如何在这个函数中使用它并追加它。
我认为您不应该修改Cpanel软件,并且tar没有密码支持。因此,您应该使用gpg
或crypt
在创建后加密.tar.gz,删除过程中的原始文件