20140223 shell scripts for backing up mysql and opendj - plembo/onemoretech GitHub Wiki

title: Shell scripts for backing up mysql and opendj link: https://onemoretech.wordpress.com/2014/02/23/shell-scripts-for-backing-up-mysql-and-opendj/ author: phil2nc description: post_id: 7031 created: 2014/02/23 03:37:22 created_gmt: 2014/02/23 08:37:22 comment_status: closed post_name: shell-scripts-for-backing-up-mysql-and-opendj status: publish post_type: post

Shell scripts for backing up mysql and opendj

Just a couple of bash scripts I threw together overnight. This one, called mydbbak.sh, dumps all MySQL datbases to text and zips them up. It also removed anything older than 30 days. Executed by the "backup" user. Target is backup's Downloads directory. [code language="bash" gutter="false"] #!/bin/bash HOST=$(hostname|cut -f1 -d.) TIMESTAMP=date +%Y%m%d%H%M BUDIR=/home/backup/Downloads FILENAME=alldb.$TIMESTAMP.sql echo "Backup MySQL on $HOST" /usr/bin/mysqldump --all-databases > ${BUDIR}/${FILENAME} cd ${BUDIR} gzip .sql find . -name ".gz" -type f -mtime +30 -exec rm -f {} ; [/code] Note the above assumes that there's a .my.cnf in the root of backup's home directory and that it contains the username and password of a database user with sufficient rights to perform the dump.

[client]
user=root
password=mydbrootpass

Here's dsbak.sh, which is run by the opendj system user to dump an LDIF of directory data every day. Target is opendj's Downloads directory. [code language="bash" gutter="false"] #!/bin/bash HOME=/home/opendj DSHOME=/opt/opendj DMPFILE=${HOME}/Downloads/prod.ldif JAVA_HOME=/usr/lib/jvm/java BASEDN="dc=example,dc=com" DBNAME=userRoot PATH=$JAVA_HOME/bin:$DSHOME/bin:$PATH export HOME DMPFILE DSHOME JAVA_HOME BASEDN DBNAME PATH echo "Backing up LDAP directory at $DSHOME" cd $DSHOME ${DSHOME}/bin/export-ldif \ -j ${HOME}/etc/pwd.txt \ -p 5444 \ -b $BASEDN \ -n $DBNAME \ -l $DMPFILE \ -t 0 \ -X [/code] Of course this one assumes an etc/pwd.txt file in opendj's home that contains the directory server's admin password.

Copyright 2004-2019 Phil Lembo