Skip to content

Instantly share code, notes, and snippets.

@yblee85
Created May 23, 2021 01:56
Show Gist options
  • Save yblee85/1f85414a51aeffec09b90add789d8bc3 to your computer and use it in GitHub Desktop.
Save yblee85/1f85414a51aeffec09b90add789d8bc3 to your computer and use it in GitHub Desktop.
ubuntu / daily backup setup
1. /usr/local/bin/mybackup.sh
#!/bin/bash
#
# couchdb Backup Script
# VER. 0.1
#If it takes a while, Diamond will grab this file and send it to Graphite to graph the duration of the backup.
date > /tmp/backup-couchdb
BASEDIR="/data/couchdb"
BACKUPDIR="/bkp/couchdb"
EXCLUDES="/data/shared/my_excludes.txt"
DATE=`date +%Y%m%d`
# Only save 1 backup - 18 hours ( == min : 1080)
BACKUPNUM="1080"
# Create required directory
if [ ! -e "${BACKUPDIR}" ] # Check Backup Directory exists.
then
mkdir -p "${BACKUPDIR}"
fi
#Back it up
GZIP=-3 /bin/tar -czf ${BACKUPDIR}/couchdb-${DATE}.tar.gz -X ${EXCLUDES} ${BASEDIR}
#Delete old stuff; sometimes you might need /usr/bin/find instead just /bin/find
/usr/bin/find ${BACKUPDIR} -mmin +${BACKUPNUM} -exec rm {} \;
rm -f /tmp/backup-couchdb
2. /data/shared/my_excludes.txt (for exclude rules)
*.view
*.compact*
3. /etc/cron.d/mybackup
# Backup couchdb database
5 0 * * * root /usr/bin/nice -n -10 /bin/bash /usr/local/bin/mybackup.sh -b /bkp/couchdb -d /data/couchdb &> /dev/null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment