Skip to content

Commit

Permalink
feat: support evn enable force restore (#3)
Browse files Browse the repository at this point in the history
* docs: fix docs error

* chore: update comment

* feat: support evn enable force restore
  • Loading branch information
Wxh16144 authored Nov 28, 2023
1 parent ccc03c5 commit ec47dac
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.en_US.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ git

## Custom Application

> Define the `[application name].cfg` configuration file and place it in the `$HOME/.backup` directory. You can customize other directories by setting the `CUSTOM_APP_CONFIG_DIR` environment variable.
> Define the `[application name].cfg` configuration file and place it in the `$HOME/.backup` directory. You can customize other directories by setting the `BACKUP_CUSTOM_APP_DIR` environment variable.
```ini
[application]
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ git

## 自定义应用程序

> 定义 `[application name].cfg` 配置文件,并放在 `$HOME/.backup` 根目录中,你可以通过设置 `CUSTOM_APP_CONFIG_DIR` 环境变量自定义其他目录。
> 定义 `[application name].cfg` 配置文件,并放在 `$HOME/.backup` 根目录中,你可以通过设置 `BACKUP_CUSTOM_APP_DIR` 环境变量自定义其他目录。
```ini
[application]
Expand Down
16 changes: 12 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,22 +73,30 @@ async function main(args: Argv, { logger }: Options) {
logger.info(`Create storage directory: ${storagePath}`);
}

const actionPrefix = args.restore ? 'Restore' : 'Backup';

for (const appConfig of appsConfigs) {
logger.info(`Backup ${c.bold(appConfig.application.name)} ...`);
logger.info(`${actionPrefix} ${c.bold(appConfig.application.name)} ...`);
await backup(
appConfig,
finalConfig,
{
logger,
force: args.restore ? false : args.force,
force: args.restore
/**
* extra care needs to be taken and double confirmation!!!
* needs to be enabled via environment variables.
*/
? (process.env.BACKUP_FORCE_RESTORE === 'true' && args.force)
: args.force,
restore: args.restore,
}
);
logger.info(`Backup ${c.bold(appConfig.application.name)} ${c.green('done')}\n`);
logger.info(`${actionPrefix} ${c.bold(appConfig.application.name)} ${c.green('done')}\n`);
}

// successful backup finished
console.log(c.green().bold(`[${new Date().toLocaleTimeString(undefined, { hour12: false })}] Successful backup finished!`));
console.log(c.green().bold(`[${new Date().toLocaleTimeString(undefined, { hour12: false })}] Successful ${actionPrefix.toLowerCase()} finished!`));
}

export default main;

0 comments on commit ec47dac

Please sign in to comment.