"use strict"; (() => { var exports = {}; exports.id = 2845; exports.ids = [2845]; exports.modules = { /***/ 4300: /***/ ((module) => { module.exports = require("buffer"); /***/ }), /***/ 2081: /***/ ((module) => { module.exports = require("child_process"); /***/ }), /***/ 6113: /***/ ((module) => { module.exports = require("crypto"); /***/ }), /***/ 7147: /***/ ((module) => { module.exports = require("fs"); /***/ }), /***/ 3685: /***/ ((module) => { module.exports = require("http"); /***/ }), /***/ 2037: /***/ ((module) => { module.exports = require("os"); /***/ }), /***/ 233: /***/ ((module, __unused_webpack_exports, __webpack_require__) => { // @ts-check /** * ============================================================================== * Imports * ============================================================================== */ const fs = __webpack_require__(7147); /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** * ============================================================================== * Main Function * ============================================================================== * @param {{ * rootFolderPath: string, * destinationFolderPath: string, * }} params - params * * @returns {boolean} operation successful or not */ module.exports = function copyFolderRecursively({ rootFolderPath , destinationFolderPath , }) { try { /** * Start Operations * * @description Start Operations */ fs.mkdirSync(destinationFolderPath); /** * Recursive Copy Function * * @description Recursive Copy Function * @param {string} srcPath - path string * @param {string} dstPath - path string */ function copyFiles(srcPath, dstPath) { const files = fs.readdirSync(srcPath); for(let i = 0; i < files.length; i++){ const file = files[i]; if (file?.match(/\..{2,5}$/)) { fs.copyFileSync(`${srcPath}/${file}`, `${dstPath}/${file}`); } else { fs.mkdirSync(`${dstPath}/${file}`, { recursive: true }); copyFiles(`${srcPath}/${file}`, `${dstPath}/${file}`); } } } copyFiles(rootFolderPath, destinationFolderPath); return true; //////////////////////////////////////////////// //////////////////////////////////////////////// //////////////////////////////////////////////// } catch (/** @type {any} */ error) { console.log(error.message); return false; } }; //////////////////////////////////////////////// //////////////////////////////////////////////// //////////////////////////////////////////////// /***/ }), /***/ 9389: /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ "default": () => (/* binding */ handler) /* harmony export */ }); /* harmony import */ var _functions_backend_copyFolderRecursively__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(233); /* harmony import */ var _functions_backend_copyFolderRecursively__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_copyFolderRecursively__WEBPACK_IMPORTED_MODULE_0__); /* harmony import */ var _functions_backend_serverError__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(2163); /* harmony import */ var _functions_backend_serverError__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_serverError__WEBPACK_IMPORTED_MODULE_1__); /* harmony import */ var _functions_backend_suAdminUserAuth__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(4432); /* harmony import */ var _functions_backend_suAdminUserAuth__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_suAdminUserAuth__WEBPACK_IMPORTED_MODULE_2__); // @ts-check const fs = __webpack_require__(7147); const os = __webpack_require__(2037); const { execSync } = __webpack_require__(2081); /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** * API handler * ============================================================================== * @type {import("next").NextApiHandler} */ async function handler(req, res) { /** * Check method * * @description Check request method and return if invalid */ if (req.method !== "GET") return res.json({ success: false, msg: "Failed" }); //////////////////////////////////////////////// //////////////////////////////////////////////// //////////////////////////////////////////////// /** * Validate Form * * @description Check if request body is valid */ const user = await _functions_backend_suAdminUserAuth__WEBPACK_IMPORTED_MODULE_2___default()(req); if (!user?.logged_in_status) { return res.json({ success: false, log: "No Logs" }); } //////////////////////////////////////////////// //////////////////////////////////////////////// //////////////////////////////////////////////// /** * Validate Form * * @description Check if request body is valid */ const backupFolder = "./.tmp/backups"; if (!fs.existsSync(backupFolder)) { fs.mkdirSync("./.tmp/backups"); } const newBackupFolderName = Date.now().toString(); fs.mkdirSync(`${backupFolder}/${newBackupFolderName}`); //////////////////////////////////////////////// //////////////////////////////////////////////// //////////////////////////////////////////////// const mysqlDumpPath = os.platform().match(/win/i) ? "'" + "C:\\Program Files\\MySQL\\MySQL Server 8.0\\bin\\mysqldump.exe" + "'" : "mysqldump"; try { /** @type {import("child_process").ExecSyncOptions} */ let execSyncOptions = { cwd: process.cwd() }; const filePath = `${backupFolder}/${newBackupFolderName}/datasquirel.sql`; if (os.platform().match(/win/i)) execSyncOptions.shell = "bash.exe"; const exe = `${mysqlDumpPath} -u ${process.env.DSQL_DB_USERNAME} -h ${process.env.DSQL_DB_HOST} -p${process.env.DSQL_DB_PASSWORD} datasquirel > ${filePath}`; console.log(`createNewBackup.js exe => ${exe}`); const dumpDb = execSync(exe, execSyncOptions); //////////////////////////////////////////////// //////////////////////////////////////////////// //////////////////////////////////////////////// fs.copyFileSync(`./jsonData/dbSchemas/main.json`, `${backupFolder}/${newBackupFolderName}/datasquirelSchema.json`); const copyUserFiles = _functions_backend_copyFolderRecursively__WEBPACK_IMPORTED_MODULE_0___default()({ rootFolderPath: `${process.env.DSQL_USER_DB_SCHEMA_PATH}`, destinationFolderPath: `${backupFolder}/${newBackupFolderName}/userSchemas` }); //////////////////////////////////////////////// //////////////////////////////////////////////// //////////////////////////////////////////////// res.json({ success: true }); //////////////////////////////////////////////// //////////////////////////////////////////////// //////////////////////////////////////////////// } catch (/** @type {any} */ error) { res.json({ success: false }); _functions_backend_serverError__WEBPACK_IMPORTED_MODULE_1___default()({ component: "/api/admin/createNewBackup/lines-73-90", message: error.message }); } //////////////////////////////////////////////// //////////////////////////////////////////////// //////////////////////////////////////////////// } /***/ }) }; ; // load runtime var __webpack_require__ = require("../../../webpack-api-runtime.js"); __webpack_require__.C(exports); var __webpack_exec__ = (moduleId) => (__webpack_require__(__webpack_require__.s = moduleId)) var __webpack_exports__ = __webpack_require__.X(0, [2163,4432], () => (__webpack_exec__(9389))); module.exports = __webpack_exports__; })();