]>
Commit | Line | Data |
---|---|---|
e1ab52d7 | 1 | import { program } from 'commander' |
f8360396 | 2 | import { CONFIG } from '@server/initializers/config' |
e1ab52d7 | 3 | import { initDatabaseModels } from '@server/initializers/database' |
e1ab52d7 | 4 | import { JobQueue } from '@server/lib/job-queue' |
f8360396 C |
5 | import { moveToExternalStorageState } from '@server/lib/video-state' |
6 | import { VideoModel } from '@server/models/video/video' | |
7 | import { VideoState, VideoStorage } from '@shared/models' | |
e1ab52d7 | 8 | |
9 | program | |
10 | .description('Move videos to another storage.') | |
11 | .option('-o, --to-object-storage', 'Move videos in object storage') | |
12 | .option('-v, --video [videoUUID]', 'Move a specific video') | |
13 | .option('-a, --all-videos', 'Migrate all videos') | |
14 | .parse(process.argv) | |
15 | ||
16 | const options = program.opts() | |
17 | ||
18 | if (!options['toObjectStorage']) { | |
19 | console.error('You need to choose where to send video files.') | |
20 | process.exit(-1) | |
21 | } | |
22 | ||
23 | if (!options['video'] && !options['allVideos']) { | |
24 | console.error('You need to choose which videos to move.') | |
25 | process.exit(-1) | |
26 | } | |
27 | ||
28 | if (options['toObjectStorage'] && !CONFIG.OBJECT_STORAGE.ENABLED) { | |
29 | console.error('Object storage is not enabled on this instance.') | |
30 | process.exit(-1) | |
31 | } | |
32 | ||
33 | run() | |
34 | .then(() => process.exit(0)) | |
35 | .catch(err => console.error(err)) | |
36 | ||
37 | async function run () { | |
38 | await initDatabaseModels(true) | |
39 | ||
4404a7c4 | 40 | JobQueue.Instance.init() |
e1ab52d7 | 41 | |
42 | let ids: number[] = [] | |
43 | ||
44 | if (options['video']) { | |
45 | const video = await VideoModel.load(options['video']) | |
46 | ||
47 | if (!video) { | |
48 | console.error('Unknown video ' + options['video']) | |
49 | process.exit(-1) | |
50 | } | |
51 | ||
52 | if (video.remote === true) { | |
53 | console.error('Cannot process a remote video') | |
54 | process.exit(-1) | |
55 | } | |
56 | ||
70956548 C |
57 | if (video.isLive) { |
58 | console.error('Cannot process live video') | |
59 | process.exit(-1) | |
60 | } | |
61 | ||
dbd9fb44 C |
62 | if (video.state === VideoState.TO_MOVE_TO_EXTERNAL_STORAGE) { |
63 | console.error('This video is already being moved to external storage') | |
64 | process.exit(-1) | |
65 | } | |
66 | ||
e1ab52d7 | 67 | ids.push(video.id) |
68 | } else { | |
69 | ids = await VideoModel.listLocalIds() | |
70 | } | |
71 | ||
72 | for (const id of ids) { | |
4fae2b1f | 73 | const videoFull = await VideoModel.loadFull(id) |
e1ab52d7 | 74 | |
9c84bf51 C |
75 | if (videoFull.isLive) continue |
76 | ||
e1ab52d7 | 77 | const files = videoFull.VideoFiles || [] |
78 | const hls = videoFull.getHLSPlaylist() | |
79 | ||
80 | if (files.some(f => f.storage === VideoStorage.FILE_SYSTEM) || hls?.storage === VideoStorage.FILE_SYSTEM) { | |
81 | console.log('Processing video %s.', videoFull.name) | |
82 | ||
1808a1f8 | 83 | const success = await moveToExternalStorageState({ video: videoFull, isNewVideo: false, transaction: undefined }) |
e1ab52d7 | 84 | |
85 | if (!success) { | |
86 | console.error( | |
87 | 'Cannot create move job for %s: job creation may have failed or there may be pending transcoding jobs for this video', | |
88 | videoFull.name | |
89 | ) | |
90 | } | |
91 | } | |
92 | ||
93 | console.log(`Created move-to-object-storage job for ${videoFull.name}.`) | |
94 | } | |
95 | } |