mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-15 14:43:46 +01:00
Merge pull request #24267 from overleaf/bg-fix-init-option
update backup script to use index when finding uninitialised projects GitOrigin-RevId: 04ce0654b3d42de1c1a9bb542482c2dd53540628
This commit is contained in:
@@ -30,7 +30,7 @@ import {
|
|||||||
projectBlobsBucket,
|
projectBlobsBucket,
|
||||||
} from '../lib/backupPersistor.mjs'
|
} from '../lib/backupPersistor.mjs'
|
||||||
import { backupGenerator } from '../lib/backupGenerator.mjs'
|
import { backupGenerator } from '../lib/backupGenerator.mjs'
|
||||||
import { promises as fs } from 'node:fs'
|
import { promises as fs, createWriteStream } from 'node:fs'
|
||||||
import os from 'node:os'
|
import os from 'node:os'
|
||||||
import path from 'node:path'
|
import path from 'node:path'
|
||||||
import projectKey from '../lib/project_key.js'
|
import projectKey from '../lib/project_key.js'
|
||||||
@@ -327,6 +327,7 @@ const optionDefinitions = [
|
|||||||
type: Boolean,
|
type: Boolean,
|
||||||
description: 'Initialize backups for all projects.',
|
description: 'Initialize backups for all projects.',
|
||||||
},
|
},
|
||||||
|
{ name: 'output', alias: 'o', type: String, description: 'Output file' },
|
||||||
{
|
{
|
||||||
name: 'start-date',
|
name: 'start-date',
|
||||||
type: String,
|
type: String,
|
||||||
@@ -686,13 +687,14 @@ export async function initializeProjects(options) {
|
|||||||
let totalProjects = 0
|
let totalProjects = 0
|
||||||
|
|
||||||
const query = {
|
const query = {
|
||||||
'overleaf.history.id': { $exists: true },
|
'overleaf.backup.lastBackedUpVersion': { $in: [null] },
|
||||||
'overleaf.backup.lastBackedUpVersion': { $exists: false },
|
}
|
||||||
'overleaf.backup.pendingChangeAt': { $exists: false },
|
|
||||||
_id: {
|
if (options['start-date'] && options['end-date']) {
|
||||||
|
query._id = {
|
||||||
$gte: objectIdFromInput(convertToISODate(options['start-date'])),
|
$gte: objectIdFromInput(convertToISODate(options['start-date'])),
|
||||||
$lt: objectIdFromInput(convertToISODate(options['end-date'])),
|
$lt: objectIdFromInput(convertToISODate(options['end-date'])),
|
||||||
},
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const cursor = client
|
const cursor = client
|
||||||
@@ -703,6 +705,18 @@ export async function initializeProjects(options) {
|
|||||||
readPreference: READ_PREFERENCE_SECONDARY,
|
readPreference: READ_PREFERENCE_SECONDARY,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if (options.output) {
|
||||||
|
console.log("Writing project IDs to file: '" + options.output + "'")
|
||||||
|
const output = createWriteStream(options.output)
|
||||||
|
for await (const project of cursor) {
|
||||||
|
output.write(project._id.toHexString() + '\n')
|
||||||
|
totalProjects++
|
||||||
|
}
|
||||||
|
output.end()
|
||||||
|
console.log('Wrote ' + totalProjects + ' project IDs to file')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
for await (const project of cursor) {
|
for await (const project of cursor) {
|
||||||
if (gracefulShutdownInitiated) {
|
if (gracefulShutdownInitiated) {
|
||||||
console.warn('graceful shutdown: stopping project initialization')
|
console.warn('graceful shutdown: stopping project initialization')
|
||||||
|
|||||||
Reference in New Issue
Block a user