1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Auto Database Backup Script 1.0

Export and Upload your Database to Offsite location with Cron

  1. MattW

    MattW Well-Known Member

    MattW submitted a new resource:

    Auto Database Backup Script (version 1.0) - Export and Upload your Database to Offsite location with Cron

    Read more about this resource...
    SneakyDave likes this.
  2. Sasa

    Sasa Active Member

    Restoring is going via phpMyadmin or something else?
  3. MattW

    MattW Well-Known Member

    If you need to restore it, I copy the remote backup back onto the server, uncompress it, and load the in via command line
    mysql -u USERNAME -p DATABASE < backupfile.sql
    Sasa likes this.
  4. Andy.N

    Andy.N Well-Known Member

  5. MattW

    MattW Well-Known Member

    Having a look at that, the only real difference between mine and Slavik's is that I have my own perl script to upload to my remote sites via FTP, where his is calling the java client to support S3. I've never used S3, but all you'd do is change my script to remove the upload.pl reference, and put the below in.

    java -jar /var/glacieruploader.jar --endpoint https://glacier.eu-west-1.amazonaws.com --vault vaultname --upload /var/backup/$suffix.tar
    Andy.N likes this.
  6. faeronsayn

    faeronsayn Well-Known Member

    Is it possible to have it automatically uploaded to your dropbox account?
  7. MattW

    MattW Well-Known Member

    I'm not sure, again, I don't use dropbox for my backups. I have a second VPS server and a NAS at home that allows FTP access.
    faeronsayn likes this.
  8. karll

    karll Well-Known Member

  9. MattW

    MattW Well-Known Member

    You can build that in using OpenSSL. I used to do that:

    # Encrypt Files using AES256
    openssl enc -aes-256-cbc -salt -in $DIR/z22seforum.$(/bin/date +%Y-%m-%d).sql.bz2 -out $DIR/z22seforum.$(/bin/date +%Y-%m-%d).sql.bz2.aes256 -pass pass:$ENCPASS
    karll likes this.
  10. Renegade

    Renegade Well-Known Member

    Is there a benefit of using a cron based backup over the WHM backup functionality?
  11. Kent

    Kent Active Member

    You can use curl for FTP uploads:
    curl -T /path/to/some.sql.gz.gpg ftp://remote.example.com --user backups:areawesome
    The day may change during the execution of the script causing it to fail. Would only likely happen if executed near midnight.
    Although AES is probably faster, I'd recommend GPG:
    gpg --encrypt -o /path/to/some.sql.gz.gpg --recipient "Example Website (Database Backup) <someone@example.org>" /path/to/some.sql.gz
    This will encrypt some.sql.gz with someone@example.org's public key and save it as some.sql.gz.gpg, which means at this point nobody else can decrypt it but the holder of the corresponding private key.
    karll, Sasa and MattW like this.
  12. erich37

    erich37 Well-Known Member

    Hi Matt,

    I am wondering if this script is also doing a backup of the Files (for backing up Avatar-images and Forum-attachments / RM attachments, etc.) ?

    Is there a chance to include the code mentioned by Brogan ?

    Many thanks!

    Last edited: Aug 8, 2013
  13. MattW

    MattW Well-Known Member

    I've replied in the other thread with a better way of backing up if you have access to rsync.

    If you wanted to back up the directories and upload via FTP using these two scripts.

    In the dbbackup.sh script, just add the instructions @Brogan posted
    #Zip Data Directory 
    /bin/tar -czf $DIR/data_$(date +%d.%m.%y).tar.gz /path/to/data 
    #Zip Internal Data Directory 
    /bin/tar -czf $DIR/internal_data_$(date +%d.%m.%y).tar.gz /path/to/internal_data
    You would then include the new data_$(date +%d.%m.%y).tar.gz and internal_data_$(date +%d.%m.%y).tar.gz files into the upload.pl script, by adding them to the array of files to be uploaded/deleted.

    Then at the end of the dbbackup.sh script, add the command to remove the files when you are done with them

    # Remove the database file now we are done
    rm $DIR/*.$(/bin/date +%Y-%m-%d).sql.bz2
    rm $DIR/internal_data_$(date +%d.%m.%y).tar.gz
    rm $DIR/data_$(date +%d.%m.%y).tar.gz
    erich37 likes this.
  14. RoldanLT

    RoldanLT Well-Known Member

    Will work even if no root access?
  15. MattW

    MattW Well-Known Member

    Yes, as it uses the local FTP account and MySQL account
    RoldanLT likes this.
  16. ncbetz

    ncbetz Formerly Noah Betz

    @MattW - is it possible to get it to backup then sent it to your local computer?
    Last edited: Jun 19, 2016
  17. MattW

    MattW Well-Known Member

    That depends on how you want to get it onto your local PC

Share This Page