The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Email DB Backup?

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

  1. Fernis

    Fernis Well-Known Member

    Joined:
    Oct 28, 2006
    Messages:
    192
    Likes Received:
    1
    Trophy Points:
    18
    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
     
    #1 Fernis, May 2, 2007
    Last edited: May 2, 2007
Loading...

Share This Page