实现GeoServer的工作空间复制Implementing workspace replication for GeoServer

实现GeoServer的工作空间复制。

概述:在使用GeoServer作为地图容器的时候,在测试机器上发布了大量的图层,需要配置新的工作空间副本的时候,还需要手动发布,经过测试,通过复制工作空间的方法非常方便。

Overview: When using GeoServer as a map container, a large number of layers were published on the testing machine. When a new workspace copy needs to be configured, manual publishing is also required. After testing, the method of copying workspaces is very convenient.

一、复制工作空间-Copy Workspace

将要复制的工作空间的文件夹复制一份在~GeoServer-Path/data_dir/workspaces下,命名为期望的工作空间名称如New-Test

Copy a folder of the workspace to be copied and place it under ‘~GeoServer Path/data-dir/workspaces’. Name it the desired workspace name, such as’ New Test’`

二、修改index.mjs中的如下参数-Modify the following parameters in index.mjs
// GeoServer 的workspace工作空间路径
const geoserverWorkspaceDir = `/path/geoserver/data_dir/workspaces`;
// 新的工作空间名称
const newWorkSpaceName = "New-Test";
三、运行index.mjs-run index.mjs
#首次执行
npm i;
#开始运行
node index.mjs

重启GeoServer新的工作空间生效。
Restart GeoServer to make it takes effect.

看到输出如下内容时运行完成:

When the following output is seen, the operation is completed:
replace over.

核心代码

import fs from "fs";
import path from "path";
const geoserverWorkspaceDir = `D:/programs/geoserver-2.18.0.9090/data_dir/workspaces`;
const newWorkSpaceName = "New-Test";

const workspaceRootDir = `${
     geoserverWorkspaceDir}/${
     newWorkSpaceName}`;
const workspaceFile = `${
     workspaceRootDir}/workspace.xml`;
const namespaceFile = `${
     workspaceRootDir}/namespace.xml`;
const stylesDir = `${
     workspaceRootDir}/styles`;
/**
 * traverse Directory
 * @param {String} directory the directory to search
 * @param {Function} callback 回调函数
 */
function traverseDirectory(directory, callback) {
   
  fs.readdir(directory, (err, files) => {
   
    if (err) throw err;
    files.forEach((file) => {
   
      let fullPath = path.join(directory, file);
      fs.stat(fullPath, (err, stats) => {
   
        if (err) throw err;
        if (stats.isDirectory()) {
   
          traverseDirectory(fullPath, callback);
        } else {
   
          if (!fullPath
  • 20
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

丷丩

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值