From 3df62ee3d01141a04640df44a52264ed322544cf Mon Sep 17 00:00:00 2001 From: Justin Yost Date: Sun, 23 Nov 2014 15:17:06 -0800 Subject: [PATCH 1/2] Updates the Backup Script to Backup SQLite Database Note only backups a single SQLite Databases Closes #8 Signed-off-by: Justin Yost --- backup.sh | 30 +++++++++++++++++++++--------- config.sh.default | 15 +++++++++++---- 2 files changed, 32 insertions(+), 13 deletions(-) diff --git a/backup.sh b/backup.sh index faa3b77..3577540 100755 --- a/backup.sh +++ b/backup.sh @@ -8,18 +8,22 @@ source ${DIR}/config.sh THEDATE=`date +%Y_%m_%d_%H_%M` #Dump Databases for Daily DB Backups -if $MYSQL_DUMP_ACTIVE; +if ${MYSQL_DUMP_ACTIVE}; then mysqldump --add-drop-table --all-databases --user=${MYSQL_DB_USERNAME} --password=${MYSQL_DB_PASSWORD} | gzip -9 > ${BACKUP_LOCAL_PATH}daily_db_backup_mysql_${THEDATE}.sql.gz fi -if $POSTGRESQL_DUMP_ACTIVE; +if ${POSTGRESQL_DUMP_ACTIVE}; then pg_dumpall --username=${POSTGRES_DB_USERNAME} | gzip -9 > ${BACKUP_LOCAL_PATH}daily_db_backup_postgresql_${THEDATE}.sql.gz fi -if $MONGODB_DUMP_ACTIVE; +if ${MONGODB_DUMP_ACTIVE}; then mongodump --host localhost --username ${MONGO_DB_USERNAME} --password ${MONGO_DB_PASSWORD} | gzip -9 > ${BACKUP_LOCAL_PATH}daily_db_backup_mongodb_${THEDATE}.sql.gz fi +if ${SQLITE_DUMP_ACTIVE}; +then + gzip -9 < ${SQLITE_PATH} > ${BACKUP_LOCAL_PATH}daily_db_backup_sqlite_${THEDATE}.gz +fi #Tar and Gzip WWW Folder for Daily Backup tar -cf ${BACKUP_LOCAL_PATH}daily_site_backup_${THEDATE}.tar -X ${DIR}/tar_exclude.txt ${WEBROOT_LOCAL_PATH} @@ -31,18 +35,22 @@ find ${BACKUP_LOCAL_PATH}daily_site_backup_* -mtime +7 -exec rm -f {} \; if [ `date +%u` = 1 ] then #Copy Daily Database Backup for Weekly DB Backups - if $MYSQL_DUMP_ACTIVE; + if ${MYSQL_DUMP_ACTIVE}; then cp ${BACKUP_LOCAL_PATH}daily_db_backup_mysql_${THEDATE}.sql.gz ${BACKUP_LOCAL_PATH}weekly_db_backup_mysql_${THEDATE}.sql.gz fi - if $POSTGRESQL_DUMP_ACTIVE; + if ${POSTGRESQL_DUMP_ACTIVE}; then cp ${BACKUP_LOCAL_PATH}daily_db_backup_postgresql_${THEDATE}.sql.gz ${BACKUP_LOCAL_PATH}weekly_db_backup_postgresql_${THEDATE}.sql.gz fi - if $MONGODB_DUMP_ACTIVE; + if ${MONGODB_DUMP_ACTIVE}; then cp ${BACKUP_LOCAL_PATH}daily_db_backup_mongodb_${THEDATE}.sql.gz ${BACKUP_LOCAL_PATH}weekly_db_backup_mongodb_${THEDATE}.sql.gz fi + if ${SQLITE_DUMP_ACTIVE}; + then + cp ${BACKUP_LOCAL_PATH}daily_db_backup_sqlite_${THEDATE}.gz ${BACKUP_LOCAL_PATH}weekly_db_backup_sqlite_${THEDATE}.gz + fi #Copy Daily Webroot Backup for Weekly Backup cp ${BACKUP_LOCAL_PATH}daily_site_backup_${THEDATE}.tar.gz ${BACKUP_LOCAL_PATH}weekly_site_backup_${THEDATE}.tar.gz @@ -54,18 +62,22 @@ fi if [ `date +%d` = 01 ] then #Copy Daily Database Backup for Monthly DB Backups - if $MYSQL_DUMP_ACTIVE; + if ${MYSQL_DUMP_ACTIVE}; then cp ${BACKUP_LOCAL_PATH}daily_db_backup_mysql_${THEDATE}.sql.gz ${BACKUP_LOCAL_PATH}monthly_db_backup_mysql_${THEDATE}.sql.gz fi - if $POSTGRESQL_DUMP_ACTIVE; + if ${POSTGRESQL_DUMP_ACTIVE}; then cp ${BACKUP_LOCAL_PATH}daily_db_backup_postgresql_${THEDATE}.sql.gz ${BACKUP_LOCAL_PATH}monthly_db_backup_postgresql_${THEDATE}.sql.gz fi - if $MONGODB_DUMP_ACTIVE; + if ${MONGODB_DUMP_ACTIVE}; then cp ${BACKUP_LOCAL_PATH}daily_db_backup_mongodb_${THEDATE}.sql.gz ${BACKUP_LOCAL_PATH}monthly_db_backup_mongodb_${THEDATE}.sql.gz fi + if ${SQLITE_DUMP_ACTIVE}; + then + cp ${BACKUP_LOCAL_PATH}daily_db_backup_sqlite_${THEDATE}.gz ${BACKUP_LOCAL_PATH}monthly_db_backup_sqlite_${THEDATE}.gz + fi #Copy Daily Webroot Backup for Monthly Backup cp ${BACKUP_LOCAL_PATH}daily_site_backup_${THEDATE}.tar.gz ${BACKUP_LOCAL_PATH}monthly_site_backup_${THEDATE}.tar.gz diff --git a/config.sh.default b/config.sh.default index 09e2956..2dac1ad 100644 --- a/config.sh.default +++ b/config.sh.default @@ -3,12 +3,19 @@ #Local Settings and Options MYSQL_DB_USERNAME=ThisIsYourMySQLUsername MYSQL_DB_PASSWORD=ThisIsYourMySQLRootPassword + POSTGRES_DB_USERNAME=ThisIsYourPostgresUsername -MONGO_DB_USERNAME=ThisIsYourMongoDBUsernameƄ + +MONGO_DB_USERNAME=ThisIsYourMongoDBUsername MONGO_DB_PASSWORD=ThisIsYourMongoDBPassword + +SQLITE_PATH=/path/to/your/sqlite/database/file + WEBROOT_LOCAL_PATH=/path/to/your/local/webroot -BACKUP_LOCAL_PATH=/path/to/where/your/backups/will/be/locally -AMAZON_S3_PATH=s3://BucketName/folder_in_bucket/ +BACKUP_LOCAL_PATH=/path/to/where/your/backups/will/be/locally/ends/with/slash/ +AMAZON_S3_PATH=s3://BucketName/folder_in_bucket/ends/with/slash/ + MYSQL_DUMP_ACTIVE=true POSTGRESQL_DUMP_ACTIVE=true -MONGODB_DUMP_ACTIVE=true \ No newline at end of file +MONGODB_DUMP_ACTIVE=true +SQLITE_DUMP_ACTIVE=false From 34aabacc85c973db5c9b058da7e9b990f77eb846 Mon Sep 17 00:00:00 2001 From: Justin Yost Date: Sun, 23 Nov 2014 15:17:35 -0800 Subject: [PATCH 2/2] Adds the ability to not upload to Amazon S3 if you don't want to Signed-off-by: Justin Yost --- backup.sh | 5 ++++- config.sh.default | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/backup.sh b/backup.sh index 3577540..a68b3f3 100755 --- a/backup.sh +++ b/backup.sh @@ -87,6 +87,9 @@ then fi #S3 Sync -s3cmd sync --delete-removed ${BACKUP_LOCAL_PATH} $AMAZON_S3_PATH +if ${AMAZON_S3_UPLOAD_ACTIVE}; +then + s3cmd sync --delete-removed ${BACKUP_LOCAL_PATH} ${AMAZON_S3_PATH} +fi echo "S3Backup Completed For: ${THEDATE}" >&2 \ No newline at end of file diff --git a/config.sh.default b/config.sh.default index 2dac1ad..cfc1661 100644 --- a/config.sh.default +++ b/config.sh.default @@ -19,3 +19,4 @@ MYSQL_DUMP_ACTIVE=true POSTGRESQL_DUMP_ACTIVE=true MONGODB_DUMP_ACTIVE=true SQLITE_DUMP_ACTIVE=false +AMAZON_S3_UPLOAD_ACTIVE=true \ No newline at end of file