Verified Commit 8e3b46de authored by kontrollanten's avatar kontrollanten Committed by Chocobozzz
Browse files

add migrate-to-object-storage-script

closes #4467
parent dd6d2a7c
import { registerTSPaths } from '../server/helpers/register-ts-paths'
registerTSPaths()
import { program } from 'commander'
import { VideoModel } from '@server/models/video/video'
import { initDatabaseModels } from '@server/initializers/database'
import { VideoState, VideoStorage } from '@shared/models'
import { moveToNextState } from '@server/lib/video-state'
import { JobQueue } from '@server/lib/job-queue'
program
.description('Migrate videos to object storage.')
.parse(process.argv)
run()
.then(() => process.exit(0))
.catch(err => console.error(err))
async function run () {
await initDatabaseModels(true)
JobQueue.Instance.init()
const videos = await VideoModel.listLocal()
const withFiles = (await Promise.all(videos.map(video => VideoModel.loadWithFiles(video.id))))
.filter(video =>
video.VideoFiles.find(vf => vf.storage === VideoStorage.FILE_SYSTEM) ||
video.VideoStreamingPlaylists.find(sp => sp.storage === VideoStorage.FILE_SYSTEM)
)
for (const video of withFiles) {
video.state = VideoState.TO_MIGRATE_TO_EXTERNAL_STORAGE
await video.save()
await moveToNextState(video, false)
console.log(`Created move-to-object-storage job for ${video.name}.`)
}
}
......@@ -419,7 +419,8 @@ const VIDEO_STATES: { [ id in VideoState ]: string } = {
[VideoState.TO_IMPORT]: 'To import',
[VideoState.WAITING_FOR_LIVE]: 'Waiting for livestream',
[VideoState.LIVE_ENDED]: 'Livestream ended',
[VideoState.TO_MOVE_TO_EXTERNAL_STORAGE]: 'To move to an external storage'
[VideoState.TO_MOVE_TO_EXTERNAL_STORAGE]: 'To move to an external storage',
[VideoState.TO_MIGRATE_TO_EXTERNAL_STORAGE]: 'To migrate to an external storage'
}
const VIDEO_IMPORT_STATES: { [ id in VideoImportState ]: string } = {
......
......@@ -11,6 +11,10 @@ import { Notifier } from './notifier'
import { addMoveToObjectStorageJob } from './video'
function buildNextVideoState (currentState?: VideoState) {
if (currentState === VideoState.TO_MIGRATE_TO_EXTERNAL_STORAGE) {
return VideoState.TO_MOVE_TO_EXTERNAL_STORAGE
}
if (currentState === VideoState.PUBLISHED) {
throw new Error('Video is already in its final state')
}
......
......@@ -4,5 +4,6 @@ export const enum VideoState {
TO_IMPORT = 3,
WAITING_FOR_LIVE = 4,
LIVE_ENDED = 5,
TO_MOVE_TO_EXTERNAL_STORAGE = 6
TO_MOVE_TO_EXTERNAL_STORAGE = 6,
TO_MIGRATE_TO_EXTERNAL_STORAGE = 7
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment