mirror of
https://github.com/overleaf/overleaf.git
synced 2025-04-22 11:47:00 +00: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:
parent
3b93efdf5c
commit
cf105cf01d
1 changed files with 20 additions and 6 deletions
|
@ -30,7 +30,7 @@ import {
|
|||
projectBlobsBucket,
|
||||
} from '../lib/backupPersistor.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 path from 'node:path'
|
||||
import projectKey from '../lib/project_key.js'
|
||||
|
@ -327,6 +327,7 @@ const optionDefinitions = [
|
|||
type: Boolean,
|
||||
description: 'Initialize backups for all projects.',
|
||||
},
|
||||
{ name: 'output', alias: 'o', type: String, description: 'Output file' },
|
||||
{
|
||||
name: 'start-date',
|
||||
type: String,
|
||||
|
@ -686,13 +687,14 @@ export async function initializeProjects(options) {
|
|||
let totalProjects = 0
|
||||
|
||||
const query = {
|
||||
'overleaf.history.id': { $exists: true },
|
||||
'overleaf.backup.lastBackedUpVersion': { $exists: false },
|
||||
'overleaf.backup.pendingChangeAt': { $exists: false },
|
||||
_id: {
|
||||
'overleaf.backup.lastBackedUpVersion': { $in: [null] },
|
||||
}
|
||||
|
||||
if (options['start-date'] && options['end-date']) {
|
||||
query._id = {
|
||||
$gte: objectIdFromInput(convertToISODate(options['start-date'])),
|
||||
$lt: objectIdFromInput(convertToISODate(options['end-date'])),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
const cursor = client
|
||||
|
@ -703,6 +705,18 @@ export async function initializeProjects(options) {
|
|||
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) {
|
||||
if (gracefulShutdownInitiated) {
|
||||
console.warn('graceful shutdown: stopping project initialization')
|
||||
|
|
Loading…
Add table
Reference in a new issue