Skip to content

Commit

Permalink
set services by env var
Browse files Browse the repository at this point in the history
  • Loading branch information
WeeJeWel committed Feb 5, 2025
1 parent de782ae commit 0ddb83c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ $ docker run \
--env GOOGLE_BACKUP_USERNAME="[email protected]" \
--env GOOGLE_BACKUP_PASSWORD="abcd efgh ijkl mnop" \
--env GOOGLE_BACKUP_FILEPATH="/backups" \
--env GOOGLE_BACKUP_SERVICES="mail,calendar,contacts" \
--volume="~/Backups/Google/:/backups/" \
ghcr.io/weejewel/google-backup
```
Expand Down
22 changes: 12 additions & 10 deletions bin/google-backup.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,24 @@ program
.option('-u, --username <username>', 'Google Username')
.option('-p, --password <password>', 'Google App Password')
.option('-f, --filepath <filepath>', 'Backup Filepath')
.option('-s, --services <services>', 'Services to backup', value => {
return value.split(',').map(value => value.trim());
}, ['mail', 'calendar', 'contacts'],
)
.option('-s, --services <services>', 'Services to backup. Defaults to mail,calendar,contacts')
.parse();

const options = program.opts();

const optionUsername = options.username ?? process.env.GOOGLE_BACKUP_USERNAME;
const optionPassword = options.password ?? process.env.GOOGLE_BACKUP_PASSWORD;
const optionFilepath = options.filepath ?? process.env.GOOGLE_BACKUP_FILEPATH;
const optionServices = (options.services ?? process.env.GOOGLE_BACKUP_SERVICES ?? 'mail,calendar,contacts').split(',').map(service => service.trim());

const googleBackup = new GoogleBackup({
username: options.username ?? process.env.GOOGLE_BACKUP_USERNAME,
password: options.password ?? process.env.GOOGLE_BACKUP_PASSWORD,
filepath: options.filepath ?? process.env.GOOGLE_BACKUP_FILEPATH,
username: optionUsername,
password: optionPassword,
filepath: optionFilepath,
});

await Promise.all([
options.services.includes('mail') && googleBackup.backupMail(),
options.services.includes('calendar') && googleBackup.backupCalendar(),
options.services.includes('contacts') && googleBackup.backupContacts(),
optionServices.includes('mail') && googleBackup.backupMail(),
optionServices.includes('calendar') && googleBackup.backupCalendar(),
optionServices.includes('contacts') && googleBackup.backupContacts(),
]);

0 comments on commit 0ddb83c

Please sign in to comment.