π A self-hostable personal dashboard built for you. Includes status-checking, widgets, themes, icon packs, a UI editor and tons more!
Vue awesomedashboarddockerhomelabhomepagemitnodejsorganizationproductivitypwaself-hostedstartpagevue
β¨ Adds option to disable config backups on save
Alicia Sykesc43712550a3e
diff --git a/docs/developing.md b/docs/developing.mdindex 9bdaec2e..97bf532f 100644--- a/docs/developing.md+++ b/docs/developing.md@@ -79,6 +79,7 @@ You can set variables either in your environment, or using the [`.env`](https://- `IS_DOCKER` - Computed automatically on build. Indicates if running in container- `VITE_APP_VERSION` - Again, set automatically using package.json during build time- `BACKUP_DIR` - Directory for conf.yml backups+- `DISABLE_CONFIG_BACKUPS` - Set to 'true' to skip the pre-save backup step (useful on read-only filesystems or where permissions don't allow it)### Environment Modesdiff --git a/docs/management.md b/docs/management.mdindex 6100c20d..3edf8aed 100644--- a/docs/management.md+++ b/docs/management.md@@ -235,7 +235,7 @@ docker run --rm -v some_volume:/volume -v /tmp:/backup alpine sh -c "rm -rf /volAll configuration and dashboard settings are stored in your `user-data/conf.yml` file. If you provide additional assets (like icons, fonts, themes, etc), these will also live in the `user-data` directory. So to backup all Dashy data, this is the only directory you need to backup.-When you save config through the UI, Dashy automatically creates a timestamped backup in `user-data/config-backups/` (configurable via the `BACKUP_DIR` env var). If you break your config, check that directory for a recent copy.+When you save config through the UI, Dashy automatically creates a timestamped backup in `user-data/config-backups/` (configurable via the `BACKUP_DIR` env var). If you break your config, check that directory for a recent copy. Backups can be disabled by setting `DISABLE_CONFIG_BACKUPS=true` (e.g. on read-only filesystems or where permissions don't allow it).Since Dashy is open source, there shouldn't be any need to backup the main container.diff --git a/docs/troubleshooting.md b/docs/troubleshooting.mdindex 44e0141f..83bd7121 100644--- a/docs/troubleshooting.md+++ b/docs/troubleshooting.md@@ -99,7 +99,7 @@ docker exec -it dashy iddocker exec -it dashy ls -la /app/user-data```-If you bind-mount from the host, make sure the host directory is owned by the container's UID (or world-writable). You can also override the backup location with the `BACKUP_DIR` env var.+If you bind-mount from the host, make sure the host directory is owned by the container's UID (or world-writable). You can also override the backup location with the `BACKUP_DIR` env var. Or, if you don't need backups at all, set `DISABLE_CONFIG_BACKUPS=true` to skip the backup step entirely.And, if you intentionally want a read-only config and don't want users to even attempt saves, set `appConfig.preventWriteToDisk: true` in `conf.yml` - Dashy will then disable both the endpoint, and the save button itself, to make the experience more explicit.diff --git a/services/save-config.js b/services/save-config.jsindex 2363e657..a222c37e 100644--- a/services/save-config.js+++ b/services/save-config.js@@ -39,20 +39,25 @@ module.exports = async (newConfig, render) => {// Resolve pathsconst userDataDirectory = process.env.USER_DATA_DIR || './user-data/';const backupLocation = process.env.BACKUP_DIR || path.join(userDataDirectory, 'config-backups');+ const backupsEnabled = process.env.DISABLE_CONFIG_BACKUPS !== 'true';const targetFile = usersFileName || 'conf.yml';const targetFilePath = path.join(userDataDirectory, targetFile);const backupBase = targetFile.replace(/\.ya?ml$/i, '');const backupFilePath = path.join(backupLocation, `${backupBase}-${Date.now()}.backup.yml`);- // Backup current config before proceeding- try {- await fsPromises.mkdir(backupLocation, { recursive: true });- await fsPromises.copyFile(targetFilePath, backupFilePath);- } catch (error) {- if (error.code !== 'ENOENT') {- respond(false, `Unable to backup ${targetFile}: ${error}`);- return;+ // Backup current config before proceeding (unless disabled via DISABLE_CONFIG_BACKUPS)+ let backedUp = false;+ if (backupsEnabled) {+ try {+ await fsPromises.mkdir(backupLocation, { recursive: true });+ await fsPromises.copyFile(targetFilePath, backupFilePath);+ backedUp = true;+ } catch (error) {+ if (error.code !== 'ENOENT') {+ respond(false, `Unable to backup ${targetFile}: ${error}`);+ return;+ }}}@@ -65,9 +70,9 @@ module.exports = async (newConfig, render) => {}// If successful, then render hasn't yet been called- call it- respond(- true,- `Successfully backed up ${targetFile} to ${backupFilePath}, `- + `and updated the contents of ${targetFilePath}`,- );+ let responseMsg = `Config saved successfully in ${targetFilePath}.`;+ if (backedUp) {+ responseMsg += ` Previous ${targetFile} was backed up to ${backupFilePath}.`;+ }+ respond(true, responseMsg);};