Welcome to Centmin Mod Community
Register Now

Auto Database Backup Script 1.0

Export and Upload your Database to Offsite location with Cron

  1. bojan horvatic

    bojan horvatic New Member

    6
    1
    3
    Feb 6, 2016
    Ratings:
    +1
    Local Time:
    5:29 PM
    damn that was fast
    thanks mate!

    however, now I'm getting this
    Code:
    Can't use an undefined value as a symbol reference at /usr/share/perl5/Net/FTP/dataconn.pm line 54.
    
    
    Hope you'll have the patience for this as well
     
  2. eva2000

    eva2000 Administrator Staff Member

    42,346
    9,560
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +14,732
    Local Time:
    2:29 AM
    Nginx 1.17.x
    MariaDB 5.5/10.x
    might need @Matt's input as I don't realy work much with perl heh
     
  3. Matt

    Matt Moderator Staff Member

    848
    372
    63
    May 25, 2014
    Rotherham, UK
    Ratings:
    +579
    Local Time:
    4:29 PM
    1.5.15
    MariaDB 10.2
    Need to see the full content of your script to see why it's not working, because line 54 is the last one of the upload script.
     
    • Informative Informative x 1
  4. bojan horvatic

    bojan horvatic New Member

    6
    1
    3
    Feb 6, 2016
    Ratings:
    +1
    Local Time:
    5:29 PM
    Hi Matt

    Here it is, and thanks :)
    btw, I need it for the single database.
    Code:
    #!/usr/bin/perl -w
    # Z22SE.co.uk
    # Used in conjunction with dbbackup.sh
    # Uploads current database backup, and removes files from remote location more than $old
    use Net::FTP;
    use Date::Manip;
    
    # FTP PARAMETERS
    $ftp_backup = 1;
    $today = UnixDate("today","%Y-%m-%d");
    $old = UnixDate("5 days ago","%Y-%m-%d");
    $ftp_host = "xxxxxxxxxxx";
    $ftp_port = "21";
    $ftp_user = "xxxxxxxxx";
    $ftp_pwd = "xxxxxxx";
    $ftp_dir = "databases";
    $dir = "/home/nginx/domains/eliterehabplacement.com/backup";
    
    # Array of Database Files to Upload
    @files = ("$dir/wp11571376db_6278.$today.sql.bz2");
    
    # Array of Old Database Files to be Deleted
    @old_files = ("wp11571376db_6278.$old.sql.bz2");
    
    &backup();
    
    # UPLOADING BACKUP TO BACKUP SERVER
    sub backup {
    if($ftp_backup == 1)
    {
            my $ftp = Net::FTP->new($ftp_host, Port => $ftp_port, Debug => 0)
              or die "Cannot connect to server: [email protected]";
    
            $ftp->login($ftp_user, $ftp_pwd)
              or die "Cannot login ", $ftp->message;
    
            $ftp->cwd($ftp_dir)
              or die "Can't CWD to remote FTP directory ", $ftp->message;
    
            $ftp->binary();
    
            foreach $file (@files) {
            $ftp->put($file)
              or warn "Upload failed ", $ftp->message;
            }
    
            foreach $oldfile (@old_files) {
            $ftp->delete($oldfile)
               or warn "Delete failed ", $ftp->message;
            }
    
            $ftp->quit();
    }
    }
    
    
     
    Last edited by a moderator: Nov 11, 2016
  5. eva2000

    eva2000 Administrator Staff Member

    42,346
    9,560
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +14,732
    Local Time:
    2:29 AM
    Nginx 1.17.x
    MariaDB 5.5/10.x
  6. bojan horvatic

    bojan horvatic New Member

    6
    1
    3
    Feb 6, 2016
    Ratings:
    +1
    Local Time:
    5:29 PM
    you are right but I'll change the pass later
    and I think only my server's IP allowed
    at least that was the idea :D
     
    • Like Like x 1
  7. Matt

    Matt Moderator Staff Member

    848
    372
    63
    May 25, 2014
    Rotherham, UK
    Ratings:
    +579
    Local Time:
    4:29 PM
    1.5.15
    MariaDB 10.2
    This might be because you are only uploading a single file, rather than an array with multiple files.

    Try this version

    Code:
    #!/usr/bin/perl -w
    # Z22SE.co.uk
    # Used in conjunction with dbbackup.sh
    # Uploads current database backup, and removes files from remote location more than $old
    use Net::FTP;
    use Date::Manip;
    
    # FTP PARAMETERS
    $ftp_backup = 1;
    $today = UnixDate("today","%Y-%m-%d");
    $old = UnixDate("5 days ago","%Y-%m-%d");
    $ftp_host = "xxxxxxxxxxx";
    $ftp_port = "21";
    $ftp_user = "xxxxxxxxx";
    $ftp_pwd = "xxxxxxx";
    $ftp_dir = "databases";
    $dir = "/home/nginx/domains/eliterehabplacement.com/backup";
    
    # Array of Database Files to Upload
    $file = "$dir/wp11571376db_6278.$today.sql.bz2";
    
    # Array of Old Database Files to be Deleted
    $oldfile = "wp11571376db_6278.$old.sql.bz2";
    
    &backup();
    
    # UPLOADING BACKUP TO BACKUP SERVER
    sub backup {
    if($ftp_backup == 1)
    {
            my $ftp = Net::FTP->new($ftp_host, Port => $ftp_port, Debug => 0)
              or die "Cannot connect to server: [email protected]";
    
            $ftp->login($ftp_user, $ftp_pwd)
              or die "Cannot login ", $ftp->message;
    
            $ftp->cwd($ftp_dir)
              or die "Can't CWD to remote FTP directory ", $ftp->message;
    
            $ftp->binary();
    
            $ftp->put($file)
              or warn "Upload failed ", $ftp->message;
    
            $ftp->delete($oldfile)
               or warn "Delete failed ", $ftp->message;
    
            $ftp->quit();
    }
    }
    
     
    • Informative Informative x 1
  8. bojan horvatic

    bojan horvatic New Member

    6
    1
    3
    Feb 6, 2016
    Ratings:
    +1
    Local Time:
    5:29 PM
    Thanks mate, I appreciate your help a lot
    Unfortunately it didn't work
    Perhaps it's something related to ovh backup thing

    got this message
    Code:
    Can't use an undefined value as a symbol reference at /usr/share/perl5/Net/FTP/dataconn.pm line 54.
    
     
  9. Matt

    Matt Moderator Staff Member

    848
    372
    63
    May 25, 2014
    Rotherham, UK
    Ratings:
    +579
    Local Time:
    4:29 PM
    1.5.15
    MariaDB 10.2
    Try changing this line:
    Code:
    my $ftp = Net::FTP->new($ftp_host, Port => $ftp_port, Debug => 0)
    to
    Code:
    my $ftp = Net::FTP->new($ftp_host, Port => $ftp_port, Debug => 0, Passive => 0)
    It's been a while since I last used this script.
     
    • Informative Informative x 1