Skip to content

Commit 9c2dbbd

Browse files
Merge pull request #7 from py-package/feature/s3
Added S3 Feature
2 parents e5ad0fc + ac49187 commit 9c2dbbd

File tree

7 files changed

+35
-176
lines changed

7 files changed

+35
-176
lines changed

CONTRIBUTING.md

Lines changed: 0 additions & 130 deletions
This file was deleted.

README.md

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<a href="https://github.com/psf/black"><img alt="Code style: black" src="https://img.shields.io/badge/code%20style-black-000000.svg"></a>
1515
</p>
1616

17-
# Masonite Backup (WIP)
17+
# Masonite Backup
1818

1919
Backup solution for Masonite.
2020

@@ -24,7 +24,7 @@ Backup solution for Masonite.
2424
- [x] Backup Files
2525
- [x] Store Backup Locally in the filesystem
2626
- [x] Email Backup
27-
- [ ] Store Backup in other Masonite Supported Storage Drivers [s3]
27+
- [x] Store Backup in other Masonite Supported Storage Drivers [s3]
2828

2929

3030
### Installation
@@ -78,11 +78,12 @@ SOURCE = {
7878
],
7979
}
8080

81+
S3_BACKUP = False # Whether or not to backup to S3.
8182
EMAIL_BACKUP = False # Whether or not to email the backup.
8283
EMAIL_BACKUP_TO = "" # The email address to send the backup to.
8384
EMAIL_SUBJECT = "System Backup" # The email subject.
8485
```
85-
> Note: Make sure you have `EMAIL_BACKUP` set to `True` and `EMAIL_BACKUP_TO` set to a valid email address, to send the backup via email. Also don't forget to setup SMTP in `config/mail.py` configuration file or in `.env` file.
86+
> Note: Make sure you have `EMAIL_BACKUP` set to `True` and `EMAIL_BACKUP_TO` set to a valid email address, to send the backup via email. Also don't forget to setup SMTP in `config/mail.py` configuration file or in `.env` file. In case you want to backup to S3, then make sure you have `S3_BACKUP` set to `True` and S3 storage configuration.
8687
8788
```sh
8889
MAIL_DRIVER=smtp
@@ -91,6 +92,11 @@ MAIL_HOST=
9192
MAIL_PORT=
9293
MAIL_USERNAME=
9394
MAIL_PASSWORD=
95+
96+
AWS_CLIENT=
97+
AWS_SECRET=
98+
AWS_BUCKET=
99+
AWS_REGION=
94100
```
95101

96102
**Backup Database and Files**
@@ -111,17 +117,7 @@ python craft backup:run --only-db
111117
python craft backup:run --only-files
112118
```
113119

114-
115-
## Contributing
116-
117-
Please read the [Contributing Documentation](CONTRIBUTING.md) here.
118-
119-
## Maintainers
120-
121-
- [x] [Yubaraj Shrestha](https://www.github.com/py-package)
122-
123120
## License
124121

125-
126122
Backup is open-sourced software licensed under the [MIT license](LICENSE).
127123

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# Versions should comply with PEP440. For a discussion on single-sourcing
99
# the version across setup.py and the project code, see
1010
# https://packaging.python.org/en/latest/single_source_version.html
11-
version="0.0.3",
11+
version="0.0.4",
1212
packages=[
1313
"backup",
1414
"backup.commands",

src/backup/Backup.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,15 @@ def files(self):
101101

102102
return f"{self.archive_file_path}.zip"
103103

104-
def email(self):
104+
def email(self, info):
105105
"""
106106
Email the backup.
107107
"""
108108

109109
if not self.backup_config.get("email_backup", False):
110110
return
111111

112+
info("Sending backup to email")
112113
if self.archive_file_path != None and pathlib.Path(f"{self.archive_file_path}.zip").exists():
113114
Mail.mailable(
114115
BackupMailable().attach(f"System Backup.zip", f"{self.archive_file_path}.zip")
@@ -120,7 +121,24 @@ def email(self):
120121
BackupMailable().attach(f"Database Backup.{ext}", self.db_file_path)
121122
).send()
122123

123-
self.cleanup()
124+
def s3(self, info):
125+
"""
126+
Upload the backup to S3.
127+
"""
128+
if not self.backup_config.get("s3_backup", False):
129+
return
130+
131+
info("Uploading backup to S3")
132+
if self.archive_file_path != None and pathlib.Path(f"{self.archive_file_path}.zip").exists():
133+
self.app.make("storage").disk("s3").put(
134+
f"System Backup.zip", f"{self.archive_file_path}.zip"
135+
)
136+
137+
if self.db_file_path != None and pathlib.Path(self.db_file_path).exists():
138+
ext = self.db_file_path.split(".")[-1]
139+
self.app.make("storage").disk("s3").put(
140+
f"Database Backup.{ext}", self.db_file_path
141+
)
124142

125143
def cleanup(self):
126144
"""

src/backup/commands/BackupRunCommand.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ def handle(self):
4040
os.remove(self.database_file_path)
4141
self.database_file_path = None
4242

43-
backup.email()
43+
backup.email(self.info)
44+
backup.s3(self.info)
45+
backup.cleanup()
46+
4447
self.info("============ Backup complete ============")
4548

4649
def validate_options(self):

src/backup/config/backup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"__pycache__",
2525
],
2626
}
27+
S3_BACKUP = False # Whether or not to backup in S3.
2728
EMAIL_BACKUP = False # Whether or not to email the backup.
2829
EMAIL_BACKUP_TO = "" # The email address to send the backup to.
2930
EMAIL_SUBJECT = "System Backup" # The email subject.

tests/integrations/config/backup.py

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)