Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions community-edition/backup_script/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const pgDumpSQLPath = path.join(dataBackupPath, "pg_dump.sql");

// get pod names
let reticulumPodName = execSync(`kubectl get pods -l=app=reticulum -n ${processedConfig.Namespace} --output jsonpath='{.items[0].metadata.name}'`);
let pgsqlPodName = execSync(`kubectl get pods -l=app=pgsql -n ${processedConfig.Namespace} --output jsonpath='{.items[0].metadata.name}'`);
let pgsqlPodName = execSync(`kubectl get pods -l=app=pgsql -n ${processedConfig.Namespace} --output jsonpath='{.items[*].metadata.name}'`);
// strip out the single quotes that Windows adds in
reticulumPodName = reticulumPodName.toString().replaceAll("'", "");
pgsqlPodName = pgsqlPodName.toString().replaceAll("'", "");
Expand All @@ -32,10 +32,19 @@ if (!fs.existsSync(rootDataBackupPath)) {

// download reticulum storage
// note: relative paths must be used for kubectl cp on windows due to this bug: https://github.com/kubernetes/kubernetes/issues/101985
execSync(`kubectl cp --retries=-1 ${reticulumPodName}:/storage ${path.relative(process.cwd(), reticulumStoragePath)} -n ${processedConfig.Namespace}`);
const reticulumOutputPath = path.relative(process.cwd(), reticulumStoragePath);
console.log(`copying reticulum files to ${reticulumOutputPath}`);
execSync(`kubectl cp --retries=-1 ${reticulumPodName}:/storage ${reticulumOutputPath} -n ${processedConfig.Namespace}`);

// create and download dump of pgsql database
// note: relative paths must be used for kubectl cp on windows due to this bug: https://github.com/kubernetes/kubernetes/issues/101985
execSync(`kubectl exec ${pgsqlPodName} -n ${processedConfig.Namespace} -- /bin/pg_dump -c ${processedConfig.PGRST_DB_URI} -f /root/pg_dump.sql`);
execSync(`kubectl cp --retries=-1 ${pgsqlPodName}:/root/pg_dump.sql ${path.relative(process.cwd(), pgDumpSQLPath)} -n ${processedConfig.Namespace}`);
execSync(`kubectl exec ${pgsqlPodName} -n ${processedConfig.Namespace} -- /bin/rm /root/pg_dump.sql`);
if (pgsqlPodName) {
// create and download dump of pgsql database
// note: relative paths must be used for kubectl cp on windows due to this bug: https://github.com/kubernetes/kubernetes/issues/101985
console.log(`dumping pgsql`);
execSync(`kubectl exec ${pgsqlPodName} -n ${processedConfig.Namespace} -- /bin/pg_dump -c ${processedConfig.PGRST_DB_URI} -f /root/pg_dump.sql`);
const pgsqlOutputPath = path.relative(process.cwd(), pgDumpSQLPath);
console.log(`copying dump to ${pgsqlOutputPath}`);
execSync(`kubectl cp --retries=-1 ${pgsqlPodName}:/root/pg_dump.sql ${pgsqlOutputPath} -n ${processedConfig.Namespace}`);
execSync(`kubectl exec ${pgsqlPodName} -n ${processedConfig.Namespace} -- /bin/rm /root/pg_dump.sql`);
} else {
console.warn('not backing up pgsql; pod not found');
}
18 changes: 12 additions & 6 deletions community-edition/get_ip/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@ const { spawnSync } = require("node:child_process");
const config = utils.readConfig();
const { stdout } = spawnSync(
"kubectl",
["-n", config.Namespace, "get", "svc", "lb", "-o", "json"],
["get", "svc", "--field-selector", "spec.type=LoadBalancer", "-A", "-o", "json"],
{ stdio: ["pipe", "pipe", "inherit"] }
);
const output = JSON.parse(stdout);
const ipAddr = output.status.loadBalancer?.ingress?.[0]?.ip;
if (ipAddr) {
console.log("load balancer external IP address:", ipAddr);
} else {
console.log("load balancer not running yet:", output.status.loadBalancer);
if (output.items.length === 0) {
console.warn("can't determine external IP address: no load balancers in cluster");
process.exit(1);
}
for (const item of output.items) {
const ipAddr = item.status.loadBalancer?.ingress?.[0]?.ip;
if (ipAddr) {
console.log("load balancer external IP address:", ipAddr);
} else {
console.log("load balancer not running yet:", output.status.loadBalancer);
}
}
5 changes: 4 additions & 1 deletion community-edition/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,12 @@ If you just need to get the external IP address of your load balancer, run

### Backing up and restoring your instance

Use `npm run backup` to backup your instance. The backup will be timestamped and placed in a `data_backups` folder.
Use `npm run backup` to back up your instance. The backup will be timestamped and placed in a `data_backups` folder.

Use `npm run restore-backup data_backup_1234567890123` to restore a backup to your instance. If you don't specify a backup, and just use `npm run restore-backup`, it will default to the latest backup.
The `hcce.yaml` file in the `community-edition` directory must match your instance.

If you run an external database instead of the `pgsql` pod, the scripts will only back up and restore the reticulum files.

## Guides from the Hubs Team and Community

Expand Down
22 changes: 15 additions & 7 deletions community-edition/restore_backup_script/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const hcce = utils.readTemplate("", "hcce.yaml");
const hcceYamlDocuments = YAML.parseAllDocuments(hcce);
hcceYamlDocuments.forEach((doc, index) => {
const jsDoc = doc.toJS();
if (jsDoc.kind === "Ingress") {
if (jsDoc?.kind === "Ingress") {
if (!jsDoc.metadata.annotations) {
jsDoc.metadata["annotations"] = {};
}
Expand Down Expand Up @@ -72,11 +72,15 @@ if (!fs.existsSync(dataBackupPath)) {

// get pod names
let reticulumPodName = execSync(`kubectl get pods -l=app=reticulum -n ${processedConfig.Namespace} --output jsonpath='{.items[0].metadata.name}'`);
let pgsqlPodName = execSync(`kubectl get pods -l=app=pgsql -n ${processedConfig.Namespace} --output jsonpath='{.items[0].metadata.name}'`);
let pgsqlPodName = execSync(`kubectl get pods -l=app=pgsql -n ${processedConfig.Namespace} --output jsonpath='{.items[*].metadata.name}'`);
// strip out the single quotes that Windows adds in
reticulumPodName = reticulumPodName.toString().replaceAll("'", "");
pgsqlPodName = pgsqlPodName.toString().replaceAll("'", "");

if (!pgsqlPodName) {
console.warn("pgsql pod not found");
}

console.log("");
console.log("restoring backup");
console.log("");
Expand All @@ -88,13 +92,17 @@ fs_object_names.forEach(fs_object_name => {
execSync(`kubectl cp --retries=-1 ${path.join(reticulumStorageRelativePath, fs_object_name)} ${reticulumPodName}:/storage -c reticulum -n ${processedConfig.Namespace}`);
});

if (pgsqlPodName) {
// upload and apply the dump of the pgsql database
// note: relative paths must be used for kubectl cp on windows due to this bug: https://github.com/kubernetes/kubernetes/issues/101985
console.log("restoring database");
execSync(`kubectl cp --retries=-1 ${path.relative(process.cwd(), pgDumpSQLPath)} ${pgsqlPodName}:/root/pg_dump.sql -n ${processedConfig.Namespace}`);
execSync(`kubectl exec ${pgsqlPodName} -n ${processedConfig.Namespace} -- /bin/psql ${processedConfig.PGRST_DB_URI} -f /root/pg_dump.sql`);
execSync(`kubectl exec ${pgsqlPodName} -n ${processedConfig.Namespace} -- /bin/rm /root/pg_dump.sql`);

const pgsqlInputPath = path.relative(process.cwd(), pgDumpSQLPath);
console.log(`restoring database from ${pgsqlInputPath}`);
execSync(`kubectl cp --retries=-1 ${pgsqlInputPath} ${pgsqlPodName}:/root/pg_dump.sql -n ${processedConfig.Namespace}`);
execSync(`kubectl exec ${pgsqlPodName} -n ${processedConfig.Namespace} -- /bin/psql ${processedConfig.PGRST_DB_URI} -f /root/pg_dump.sql`);
execSync(`kubectl exec ${pgsqlPodName} -n ${processedConfig.Namespace} -- /bin/rm /root/pg_dump.sql`);
} else {
console.warn('not restoring database');
}

// restart the Hubs instance so it doesn't error out when visited and maintenance mode is no longer applied
fs.rmSync(path.join(process.cwd(), maintenanceModeHcceFileName));
Expand Down