Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

Email DB Backup?

Discussion in 'E-mail Discussion' started by Fernis, May 2, 2007.

  1. Fernis

    Fernis Well-Known Member

    Joined:
    Oct 28, 2006
    Messages:
    193
    Likes Received:
    1
    Trophy Points:
    168
    Is it possible to have the bash script, that is executed using a cron job, posted below email the DB backup to me as well as saving a copy to the server as it is currently doing?

    # Script Function:
    # This bash script backups up the "DBname" and "DBname" db everyday at 4am with a file name time stamp and tar.gz zips the file.
    # The "DBname" db will be saved in /backups/database_backups/"DBname"/
    # The "DBname" db will be stored in /backups/database_backups/"DBname"/
    # Db backups older than 30 days will be deleted.

    #[Changes Directory]
    cd /home/"accountname"/backups/

    #[Old DB Deletion Script]
    find /home/"accountname"/backups/database_backups -name "*.tar.gz" -mtime +30 -exec rm -f {} \;

    #[Stamps the file name with a date]
    TIMESTAMP=`date +%m-%d-%y-%H%M`


    #[DB Backup Scripts]

    # "DBname"
    HOST=localhost
    DBNAME="DBname"
    USER="DBusername"
    PASSWORD="DBpassword"
    DUMP_PATH=/home/"accountname"/backups/database_backups/"DBname"
    mysqldump --opt -c -e -Q -h$HOST -u$USER -p$PASSWORD $DBNAME > $DBNAME.sql
    tar czpf $DUMP_PATH/$DBNAME.$TIMESTAMP.tar.gz $DBNAME.sql
    rm -f $DBNAME.sql

    # "DBname"
    HOST=localhost
    DBNAME="DBname"
    USER="DBusername"
    PASSWORD="DBpassword"
    DUMP_PATH=/home/"accountname"/backups/database_backups/"DBname"
    mysqldump --opt -c -e -Q -h$HOST -u$USER -p$PASSWORD $DBNAME > $DBNAME.sql
    tar czpf $DUMP_PATH/$DBNAME.$TIMESTAMP.tar.gz $DBNAME.sql
    rm -f $DBNAME.sql
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
    #1 Fernis, May 2, 2007
    Last edited: May 2, 2007
Loading...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice