Skip to content

Commit

Permalink
Merge pull request #10 from jtyost2/f/sqlite-backups
Browse files Browse the repository at this point in the history
F/sqlite backups
  • Loading branch information
justinyost committed Nov 23, 2014
2 parents f0fca75 + 34aabac commit d139fee
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 14 deletions.
35 changes: 25 additions & 10 deletions backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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
Expand All @@ -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
Expand All @@ -75,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
16 changes: 12 additions & 4 deletions config.sh.default
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,20 @@
#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
MONGODB_DUMP_ACTIVE=true
SQLITE_DUMP_ACTIVE=false
AMAZON_S3_UPLOAD_ACTIVE=true

0 comments on commit d139fee

Please sign in to comment.