Created
November 5, 2015 20:40
-
-
Save CNG/a5c700de8b371f1b0543 to your computer and use it in GitHub Desktop.
Mongo dump from Perl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use DateTime; | |
use File::Path; | |
use DBI; | |
use File::Basename; | |
require File::Spec->catfile(dirname(__FILE__),'nearme-dump.cnf'); | |
my $root = '/mnt/nfs/bak/nearme'; | |
my $time = DateTime->now()->ymd(); | |
my $path = File::Spec->catfile($root,$time); | |
rmtree($path); | |
unlink("$path.tgz"); | |
die "Could not create '$path': $@\n" if (!-d $path && !File::Path::mkpath($path)); | |
my $exec = "mongodump --username=$user --password=$pass --host=$host --db=$name --out=$path > /dev/null 2>&1"; | |
my $stat = `$exec`; | |
#print "Dump of $name failed: $stat\n" if ($stat); | |
chdir($root); | |
my $stat = `tar -czf $path.tgz $time`; | |
print "Archive of $path failed: $stat\n" if ($stat); | |
rmtree($path); | |
$time = DateTime->now()->subtract('days' => 7)->ymd(); | |
$path = File::Spec->catfile($root,$time); | |
unlink("$path.tgz"); | |
1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment