pkgacct set destination folder with variable date format
Hi There,
I am adapting this code from a feature request
Change WHM cpanel Backup to allow Database only backups
I am trying to get it to create the backup in /backup/2016-10-15 for example but it just does not work. If i set it to just use /backup/ it DOES word correctly
so I don't understand what is going wrong by me trying to add a subfolder here (this way i can run a cron and create multiple backup points instead of overwriting each time) the output of the print statement shows me the path formatted correctly as well. any help is greatly appreciated. thanks
#!/usr/bin/perl
BEGIN { unshift @INC, '/usr/local/cpanel'; }
use Cpanel::Config::Users ();
my @cpusers = Cpanel::Config::Users::getcpusers();
use Time::Piece;
my $date = localtime->strftime('%Y-%m-%d');
my $backupdir = "/backup/" . $date;
print $backupdir;
foreach my $user (@cpusers) {
my $cmd = "/scripts/pkgacct --skiphomedir $user $backupdir";
open my $OUTPUT, '-|', $cmd or next;
while (<$OUTPUT>) {
print $_;
}
close $OUTPUT or next;
}
I am trying to get it to create the backup in /backup/2016-10-15 for example but it just does not work. If i set it to just use /backup/ it DOES word correctly
my $backupdir = "/backup/";
so I don't understand what is going wrong by me trying to add a subfolder here (this way i can run a cron and create multiple backup points instead of overwriting each time) the output of the print statement shows me the path formatted correctly as well. any help is greatly appreciated. thanks
-
thanks a lot. I added in the code but i get the error that the directory could not be created? could it be because /backup already exists (its a mounted separate drive) also you have an extra } at the end there. actually i think i got it with this instead does this make sense? #!/usr/bin/perl BEGIN { unshift @INC, '/usr/local/cpanel'; } use Cpanel::Config::Users (); my @cpusers = Cpanel::Config::Users::getcpusers(); use Time::Piece; my $date = localtime->strftime('%Y-%m-%d'); my $backupdir = "/backup/" . $date . "/"; print $backupdir; mkdir $backupdir; foreach my $user (@cpusers) { my $cmd = "/scripts/pkgacct --skiphomedir $user $backupdir"; open my $OUTPUT, '-|', $cmd or next; while (<$OUTPUT>) { print $_; } close $OUTPUT or next; }
thanks!0
Please sign in to leave a comment.
Comments
1 comment