CHips L MINI SHELL

CHips L pro

Current Path : /proc/2/cwd/proc/2/root/proc/2/root/scripts/
Upload File :
Current File : //proc/2/cwd/proc/2/root/proc/2/root/scripts/convert_metadata_names

#!/usr/local/cpanel/3rdparty/bin/perl

# cpanel - scripts/convert_metadata_names            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::convert_metadata_names;

use strict;
use warnings;
use File::Glob;
use Cpanel::Backup::Config  ();
use Cpanel::FileUtils::Path ();

# Most of this taken directly from scripts/backups_create_metadata

# get all backup dirs under the main backup
my %backup_dirs_hash;
my $bu_dirs_ar = Cpanel::Backup::Config::get_backup_dirs();
foreach my $budir ( @{$bu_dirs_ar} ) {
    foreach my $dir (
        File::Glob::bsd_glob( $budir . "/2*/accounts" ),
        File::Glob::bsd_glob( $budir . "/monthly/2*/accounts" ),
        File::Glob::bsd_glob( $budir . "/weekly/2*/accounts" ),
        File::Glob::bsd_glob( $budir . "/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 ) {
    my @metadata_files = File::Glob::bsd_glob( $dir . "/accounts/*.meta" );
    foreach my $metadata_file (@metadata_files) {
        if ( -d $metadata_file ) {
            print "Not converting user directory with collision prone name: $metadata_file\n";
        }
        elsif ( -f $metadata_file ) {
            my $new_file = $metadata_file;
            $new_file =~ s/\.meta$/\-\=\-meta/;
            if ( -f $new_file ) {
                print "New format metadata file already exists, removing old format one to avoid leaving cruft behind\n";
                unlink $metadata_file;
            }
            else {
                print "Converting $metadata_file to $new_file\n";
                rename( $metadata_file, $new_file );
            }
        }
    }

}

1;

Copyright 2K16 - 2K18 Indonesian Hacker Rulez