-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
84adcf9
commit 7e3a991
Showing
1 changed file
with
85 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,87 @@ | ||
# s3-backup | ||
# S3Backup | ||
|
||
Flexible python based backup utility for storing to S3 | ||
|
||
**NOTE:** Currently in early development - doesn't actually do anything yet! :) | ||
## About | ||
|
||
This is a small python script to handle performing backups cross platform | ||
|
||
## Features | ||
|
||
It supports the following features: | ||
|
||
* Plan based backups | ||
* Custom command run pre-backup | ||
* Storing to S3 | ||
* Emailing the result of the backup plans | ||
* Python standard logging framework | ||
|
||
## Configuration | ||
|
||
The backup utility is configured through the use of a JSON configuration file | ||
|
||
```json | ||
{ | ||
"AWS_KEY": "this is a key", | ||
"AWS_SECRET": "this is a secret", | ||
"AWS_BUCKET": "this is a bucket", | ||
"AWS_REGION": "this is a region", | ||
"EMAIL_FROM": "source@address.com", | ||
"EMAIL_TO": "recipient@address.com", | ||
"Plans": [ | ||
{ | ||
"Name": "MySQL Backup", | ||
"Command": "mysqldump -u bob -p password > mysql_backup.sql", | ||
"Src": "c:/mysql_backup.sql", | ||
"OutputPrefix": "main_db" | ||
}, | ||
{ | ||
"Name": "Website Backup", | ||
"Src": ["c:/website/*.html", "C:/website/src/**/*"], | ||
"OutputPrefix": "website" | ||
} | ||
] | ||
} | ||
``` | ||
|
||
If emails are not required, then omit the `EMAIL_FROM` and `EMAIL_TO` fields of the configuration file. | ||
|
||
*Note*: When on Windows, it is better to pass the paths using forward slashes (/) as then escaping isn't required (as with backslashes). The script will normalize the paths in these cases. | ||
However, when providing the command, if paths are required they will need to be double escaped. | ||
|
||
## Usage | ||
|
||
You will need to set up an AWS account if you do not have one, and then obtain AWS keys for an IAM account which has the following privileges: | ||
|
||
* S3 full access (for writing to the storage bucket) | ||
* SES full access (for sending emails) | ||
|
||
Run the backup tool using the following method: | ||
|
||
```python | ||
import logging | ||
import os | ||
import sys | ||
from S3Backup import S3BackupTool | ||
|
||
script_path = os.path.dirname(os.path.realpath(__file__)) + '/' | ||
|
||
# Log to file | ||
#logging.basicConfig(format='%(asctime)s - %(levelname)s - %(name)s - %(message)s', | ||
# filename=script_path + "s3backup.log", level=logging.INFO) | ||
|
||
# Log to stdout | ||
logging.basicConfig(stream=sys.stdout, level=logging.DEBUG) | ||
|
||
s3backup = S3BackupTool("config.json") | ||
|
||
s3backup.run_plans() | ||
``` | ||
|
||
See `test.py` in the `src` folder for an example. | ||
|
||
## Future Improvements | ||
|
||
These are some of the planned future improvements: | ||
|
||
* Run multiple pre-backup commands (by providing an array) |