Edit File: backups_create_metadata
#!/usr/local/cpanel/3rdparty/bin/perl # cpanel - backups_create_metadata Copyright 2017 cPanel, Inc. # All rights Reserved. # copyright@cpanel.net http://cpanel.net # This code is subject to the cpanel license. Unauthorized copying is prohibited package scripts::backups_create_metadata; use strict; use warnings; use Cpanel::Backup::StreamFileList (); use Cpanel::FileUtils::Path (); use Cpanel::Logger (); use Getopt::Long (); use File::Glob (); use File::Spec (); use Try::Tiny; sub _help { my ($msg) = @_; print qq{$msg Usage: $0 [--all=/backup | --backup=/backup/monthly/2017-03-01 [ --user=user ] ] --all=/backup - Create meta data for all backups in this directory. --backup=/backup/monthly/2017-03-01 - Create meta data for all users in this backup directory. --user=user - Create meta data for this user only in the --backup NOTE: --all is not compatible with --backup, and --user can only be used with --backup }; exit 0; } sub _invalid_parms { _help("invalid parameters"); die "Invalid Command Line Parameters\n"; } our $all; our $backup; our $user; our $logger; sub _output { my ($line) = @_; print $line . "\n"; return; } sub script { my (@args) = @_; $logger //= Cpanel::Logger->new( { 'alternate_logfile' => '/dev/stdout' } ); my $opts = Getopt::Long::GetOptionsFromArray( \@args, 'all=s' => \$all, 'backup=s' => \$backup, 'user=s' => \$user, ) or _invalid_parms(); _help("all or backup required") if !$all && !$backup; _help("all or backup but not both") if $all && $backup; _help("user cannot be used with all") if $user && $all; if ($all) { # get all backup dirs under the main backup my %backup_dirs_hash; foreach my $dir ( File::Glob::bsd_glob( $all . "/2*/accounts" ), File::Glob::bsd_glob( $all . "/monthly/2*/accounts" ), File::Glob::bsd_glob( $all . "/weekly/2*/accounts" ), File::Glob::bsd_glob( $all . "/incremental/accounts" ) ) { my ( $xdir, $accounts ) = Cpanel::FileUtils::Path::dir_and_file_from_path($dir); $backup_dirs_hash{$xdir} = 1; } foreach my $dir ( sort keys %backup_dirs_hash ) { try { Cpanel::Backup::StreamFileList::create_metadata_for_backup( $dir, undef ); } catch { $logger->warn("Failed to create metadata for $dir"); } } } elsif ($backup) { if ($user) { try { Cpanel::Backup::StreamFileList::create_metadata_for_user_backup( $backup, undef, $user ); } catch { $logger->warn("Failed to create metadata for $backup"); } } else { try { Cpanel::Backup::StreamFileList::create_metadata_for_backup( $backup, undef ); } catch { $logger->warn("Failed to create metadata for $backup"); } } } return 1; } exit( script(@ARGV) ? 0 : 1 ) unless caller();