Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #@author Andrey Knupp Vital, Projects Utils
- use strict;
- use warnings;
- use File::Spec::Functions qw( catfile );
- use File::Copy::Recursive qw(fcopy rcopy dircopy fmove rmove dirmove);
- system ( "cls" ) ;
- print STDOUT "Initializing .... [ OK ] \n";
- print "Full project path: " ;
- chomp ( my $path = <STDIN> ) ;
- if ( $path eq '' ) {
- print STDOUT "\nInvalid path....: Ok \n" ;
- message ( 25 , 5 , '.' , "Exiting Now" , ': Ok' ) ;
- exit 1 ;
- } else {
- my $dbname ;
- my $from;
- print "Assuming the <$path> path to the main course for the project ..\n";
- print "Project dir in <$path> ? dir name: " ;
- chomp ( my $dir = <STDIN> ) ;
- if ( ! $dir eq '' ) {
- print "Assuming the <$dir> name to the database, you can change it \n";
- }
- print "Backup database ? (Y/N) " ;
- chomp ( my $dbc = <STDIN> ) ;
- if ( ! $dir eq '' && $dbc eq 'Y' ) {
- print "Database name ? assumed <$dir>, set: " ;
- chomp ( my $db = <STDIN> ) ;
- if ( ! $db eq '' ) {
- $dbname = $db ;
- print "Assumed schema name as <$db> \n" ;
- } else {
- $dbname = $dir ;
- print "Assumed schema name as <$dir> \n" ;
- }
- }
- print "Initializing validations ... [ OK ] \n" ;
- print "Now checking if <$path/$dir> exists ... [ OK ] \n" ;
- if ( -d "$path/$dir" ) {
- print "Yeah, directory <$path/$dir> exists ... [ OK ] \n" ;
- $from = "$path/$dir";
- } else {
- print "Opz, directory <$path/$dir> does not exists ... [ Fail ] \n" ;
- message ( 25 , 5 , '.' , "Exiting Now" , ': Ok' ) ;
- exit 1 ;
- }
- our $bckPath = "";
- sub dir {
- my ( $sec , $min , $hour , $mday , $mon , $year , $wday , $yday , $isdst ) = localtime( time );
- $year += 1900 ; $mon++ ;
- $mday = '0' . $mday if ($mday < 10 );
- $mon = '0' . $mon if ($mon < 10 );
- my $dirName = "$year-$mon-$mday";
- print "Ok .. now we have to set the backup dir .. [ OK ] \n" ;
- print "I have a suggest for you, use dir name as <$dirName> ? ( Y/N ) ";
- chomp ( my $choise = <STDIN> ) ;
- if ( $choise eq '' or $choise eq 'N' ) {
- print "You choise <NO> .. now you have to set it manually ... [ OK ]\n";
- print "Enter backup directory name: " ;
- chomp ( my $dirName = <STDIN> ) ;
- if ( ! $dirName eq '' ) {
- print "Well .. now backup directory name as <$dirName> \n" ;
- $dir = $dirName ;
- } else {
- print STDOUT "\nInvalid directory name ....: [ Ok ] \n" ;
- message ( 25 , 5 , '.' , "Exiting Now " , " [ Ok ] \n" ) ;
- print "Bye, bye !" ;
- exit 1 ;
- }
- } else {
- if ( $choise eq 'Y' ) {
- print "Well .. now backup directory name as <$dirName> \n" ;
- $dir = $dirName ;
- } else {
- print "Please .. answer Y/N or press enter for <N> \n";
- dir();
- }
- }
- print "Finally, you have to set now the backup path/<$dir> .. \n" ;
- print "Sure .. now we have to set the backup path, set as: " ;
- chomp ( my $backupPath = <STDIN> ) ;
- if ( ! $backupPath eq '' ) {
- mkdir( "$backupPath/$dir" ) or die( "Cannot create a folder called '$backupPath/$dir' ... [ Error ] \n");
- print "Creating the directory ... [ OK ] \n" ;
- print "Directory <$backupPath/$dir> created succesfully ! .. \n" ;
- } else {
- print "Opz, path can't be null ... [ Fail ] \n" ;
- message ( 25 , 5 , '.' , "Exiting Now" , ': Ok' ) ;
- exit 1 ;
- }
- $bckPath = "$backupPath/$dir" ;
- }
- dir();
- if ( $dbc eq 'Y' ) {
- print "Dumping database $dbname .. initializing ... [ OK ] \n" ;
- print "UserName for schema <$dbname>: " ;
- chomp ( my $username = <STDIN> ) ;
- print "PassWord for schema <$dbname>: " ;
- chomp ( my $password = <STDIN> ) ;
- `mysqldump -u $username -p$password $dbname > $bckPath/$dbname.sql`;
- print "Database <$dbname:$bckPath/$dbname.sql> dumped sucessfully ! [ OK ] \n";
- }
- print "Copying directory <$from> to <$bckPath> .... \n" ;
- if ( dircopy ( $from , $bckPath ) ) {
- print "Done ....... [ OK ] \n";
- if ( $dbc eq 'Y' ) {
- message ( 25 , 0 , '.' , 'Database backup' , '[ OK ]' );
- }
- message ( 25 , 0 , '.' , 'Project backup' , '[ OK ]' );
- print "Bye, bye";
- }
- }
- sub message {
- my ( $count , $start , $char , $append , $prepend ) = @_ ;
- print STDOUT "$append" ;
- for ( my $i = $start ; $i < $count ; ++ $i ) {
- if ( ! $char eq '' ) {
- if ( $i eq ( $count - 1 ) ) {
- print STDOUT "$prepend \n";
- } else {
- print STDOUT $char ;
- }
- } else {
- exit 1;
- }
- }
- }
Add Comment
Please, Sign In to add comment