aboutsummaryrefslogtreecommitdiffhomepage
path: root/scripts/create-move-video-storage-job.ts
diff options
context:
space:
mode:
authorkontrollanten <6680299+kontrollanten@users.noreply.github.com>2021-11-09 11:05:35 +0100
committerGitHub <noreply@github.com>2021-11-09 11:05:35 +0100
commite1ab52d7ec7370a6f9f5937192d6003206af1ac0 (patch)
treeaecc8b696b0021e073fd205dd6e126fb4f178e8f /scripts/create-move-video-storage-job.ts
parentc49c366ac320fe5ac3dc08f5891fe5898c1b34e3 (diff)
downloadPeerTube-e1ab52d7ec7370a6f9f5937192d6003206af1ac0.tar.gz
PeerTube-e1ab52d7ec7370a6f9f5937192d6003206af1ac0.tar.zst
PeerTube-e1ab52d7ec7370a6f9f5937192d6003206af1ac0.zip
Add migrate-to-object-storage script (#4481)
* add migrate-to-object-storage-script closes #4467 * add migrate-to-unique-playlist-filenames script * fix(migrate-to-unique-playlist-filenames): update master/segments256 run updateMasterHLSPlaylist and updateSha256VODSegments after file rename. * Improve move to object storage scripts * PR remarks Co-authored-by: Chocobozzz <me@florianbigard.com>
Diffstat (limited to 'scripts/create-move-video-storage-job.ts')
-rw-r--r--scripts/create-move-video-storage-job.ts86
1 files changed, 86 insertions, 0 deletions
diff --git a/scripts/create-move-video-storage-job.ts b/scripts/create-move-video-storage-job.ts
new file mode 100644
index 000000000..505bbd61b
--- /dev/null
+++ b/scripts/create-move-video-storage-job.ts
@@ -0,0 +1,86 @@
1import { registerTSPaths } from '../server/helpers/register-ts-paths'
2registerTSPaths()
3
4import { program } from 'commander'
5import { VideoModel } from '@server/models/video/video'
6import { initDatabaseModels } from '@server/initializers/database'
7import { VideoStorage } from '@shared/models'
8import { moveToExternalStorageState } from '@server/lib/video-state'
9import { JobQueue } from '@server/lib/job-queue'
10import { CONFIG } from '@server/initializers/config'
11
12program
13 .description('Move videos to another storage.')
14 .option('-o, --to-object-storage', 'Move videos in object storage')
15 .option('-v, --video [videoUUID]', 'Move a specific video')
16 .option('-a, --all-videos', 'Migrate all videos')
17 .parse(process.argv)
18
19const options = program.opts()
20
21if (!options['toObjectStorage']) {
22 console.error('You need to choose where to send video files.')
23 process.exit(-1)
24}
25
26if (!options['video'] && !options['allVideos']) {
27 console.error('You need to choose which videos to move.')
28 process.exit(-1)
29}
30
31if (options['toObjectStorage'] && !CONFIG.OBJECT_STORAGE.ENABLED) {
32 console.error('Object storage is not enabled on this instance.')
33 process.exit(-1)
34}
35
36run()
37 .then(() => process.exit(0))
38 .catch(err => console.error(err))
39
40async function run () {
41 await initDatabaseModels(true)
42
43 JobQueue.Instance.init(true)
44
45 let ids: number[] = []
46
47 if (options['video']) {
48 const video = await VideoModel.load(options['video'])
49
50 if (!video) {
51 console.error('Unknown video ' + options['video'])
52 process.exit(-1)
53 }
54
55 if (video.remote === true) {
56 console.error('Cannot process a remote video')
57 process.exit(-1)
58 }
59
60 ids.push(video.id)
61 } else {
62 ids = await VideoModel.listLocalIds()
63 }
64
65 for (const id of ids) {
66 const videoFull = await VideoModel.loadAndPopulateAccountAndServerAndTags(id)
67
68 const files = videoFull.VideoFiles || []
69 const hls = videoFull.getHLSPlaylist()
70
71 if (files.some(f => f.storage === VideoStorage.FILE_SYSTEM) || hls?.storage === VideoStorage.FILE_SYSTEM) {
72 console.log('Processing video %s.', videoFull.name)
73
74 const success = await moveToExternalStorageState(videoFull, false, undefined)
75
76 if (!success) {
77 console.error(
78 'Cannot create move job for %s: job creation may have failed or there may be pending transcoding jobs for this video',
79 videoFull.name
80 )
81 }
82 }
83
84 console.log(`Created move-to-object-storage job for ${videoFull.name}.`)
85 }
86}