mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-03 21:43:21 +00:00 
			
		
		
		
	This solves a common migration problem for folks who cut corners when first setting up Zulip. Fixes #11294.
		
			
				
	
	
		
			32 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			32 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
 | 
						|
import argparse
 | 
						|
import os
 | 
						|
import tempfile
 | 
						|
from typing import Any
 | 
						|
 | 
						|
from django.core.management.base import BaseCommand, CommandParser, CommandError
 | 
						|
from django.conf import settings
 | 
						|
 | 
						|
from zerver.lib.transfer import transfer_uploads_to_s3
 | 
						|
 | 
						|
class Command(BaseCommand):
 | 
						|
    help = """Transfer uploads to S3 """
 | 
						|
 | 
						|
    def add_arguments(self, parser: CommandParser) -> None:
 | 
						|
        parser.add_argument('--processes',
 | 
						|
                            dest='processes',
 | 
						|
                            action="store",
 | 
						|
                            default=6,
 | 
						|
                            help='Processes to use for exporting uploads in parallel')
 | 
						|
 | 
						|
    def handle(self, *args: Any, **options: Any) -> None:
 | 
						|
        num_processes = int(options['processes'])
 | 
						|
        if num_processes < 1:
 | 
						|
            raise CommandError('You must have at least one process.')
 | 
						|
 | 
						|
        if not settings.LOCAL_UPLOADS_DIR:
 | 
						|
            raise CommandError('Please set the value of LOCAL_UPLOADS_DIR.')
 | 
						|
 | 
						|
        transfer_uploads_to_s3(num_processes)
 | 
						|
        print("Transfer to S3 completed successfully.")
 |