Skip to content

armgit / dashy

Public Imported from GitHub
0

πŸš€ A self-hostable personal dashboard built for you. Includes status-checking, widgets, themes, icon packs, a UI editor and tons more!

✨ Put config backups in own directory

Alicia Sykesf295958c443a
diff --git a/.env b/.env
index 612a0937..c9ca94a2 100644
--- a/.env
+++ b/.env
@@ -52,7 +52,7 @@
# VUE_APP_VERSION=2.0.0
# Directory for conf.yml backups
-# BACKUP_DIR=./user-data/
+# BACKUP_DIR=./user-data/config-backups
# Setup any other user defined vars by prepending VUE_APP_ to the var name
# VUE_APP_pihole_ip=http://your.pihole.ip
diff --git a/services/save-config.js b/services/save-config.js
index f946be54..1665c3c4 100644
--- a/services/save-config.js
+++ b/services/save-config.js
@@ -14,18 +14,23 @@ module.exports = async (newConfig, render) => {
return configObj.filename.replaceAll('/', '').replaceAll('..', '');
};
+ // Path to config file (with navigational characters stripped)
const usersFileName = makeSafeFileName(newConfig);
+ // Path to user data directory
+ const userDataDirectory = process.env.USER_DATA_DIR || './user-data/';
+
// Define constants for the config file
const settings = {
- defaultLocation: process.env.USER_DATA_DIR || './user-data/',
+ defaultLocation: userDataDirectory,
+ backupLocation: process.env.BACKUP_DIR || path.join(userDataDirectory, 'config-backups'),
defaultFile: 'conf.yml',
filename: 'conf',
backupDenominator: '.backup.yml',
};
// Make the full file name and path to save the backup config file
- const backupFilePath = `${path.normalize(process.env.BACKUP_DIR || settings.defaultLocation)
+ const backupFilePath = `${path.normalize(settings.backupLocation)
}/${usersFileName || settings.filename}-`
+ `${Math.round(new Date() / 1000)}${settings.backupDenominator}`;
@@ -45,15 +50,20 @@ module.exports = async (newConfig, render) => {
message: !success ? errorMsg : getSuccessMessage(),
});
- // Makes a backup of the existing config file
+ // Create a backup of current config, and if backup dir doesn't yet exist, create it
await fsPromises
- .copyFile(defaultFilePath, backupFilePath)
- .catch((error) => render(getRenderMessage(false, `Unable to backup ${settings.defaultFile}: ${error}`)));
+ .mkdir(settings.backupLocation, { recursive: true })
+ .then(() => fsPromises.copyFile(defaultFilePath, backupFilePath))
+ .catch((error) => render(
+ getRenderMessage(false, `Unable to backup ${settings.defaultFile}: ${error}`),
+ ));
// Writes the new content to the conf.yml file
await fsPromises
.writeFile(defaultFilePath, newConfig.config.toString(), writeFileOptions)
- .catch((error) => render(getRenderMessage(false, `Unable to write to ${settings.defaultFile}: ${error}`)));
+ .catch((error) => render(
+ getRenderMessage(false, `Unable to write to ${settings.defaultFile}: ${error}`),
+ ));
// If successful, then render hasn't yet been called- call it
await render(getRenderMessage(true));