@@ -534,16 +534,35 @@ def create_backup(
534534
535535 # If backup path is not defined, skip this step
536536 if not backup_path :
537- logger .warning ("Skipping backup: 'backup_path' not defined in config." )
537+ msg = "Skipping backup: 'backup_path' not defined in config."
538+ logger .warning (msg )
538539 return
539540
540541 # Build backup filename and path
541542 deploy_path = config ["deploy_path" ]
542543 site_name = config ["name" ]
543544 timestamp = datetime .now (UTC ).strftime ("%Y%m%d%H%M%S" )
544- backup_file = os .path .join (backup_path , f"{ site_name } _{ timestamp } .tar.gz" )
545+ backup_file = os .path .join (
546+ backup_path , f"{ site_name } _{ timestamp } .tar.gz"
547+ )
548+
549+ # Check if current symlink exists (active deployment)
550+ result = c .run (
551+ f"test -L { deploy_path } /current && echo 'exists'" ,
552+ hide = True , warn = True
553+ )
554+
555+ if not result or not result .ok or result .stdout .strip () != 'exists' :
556+ msg = (
557+ "Skipping backup: No active deployment found "
558+ "(current symlink doesn't exist)."
559+ )
560+ logger .warning (msg )
561+ return
545562
546- logger .info (f"Creating backup for site '{ site_name } ' at { backup_file } " )
563+ logger .info (
564+ f"Creating backup for site '{ site_name } ' at { backup_file } "
565+ )
547566
548567 # Ensure backup directory exists
549568 remote_user = c .run ("whoami" , hide = True )
@@ -554,16 +573,29 @@ def create_backup(
554573
555574 # Create compressed backup using tar
556575 try :
557- c .run (f"tar -czf { backup_file } -C { deploy_path } ." )
558- logger .info (f"Backup created: { backup_file } " )
576+ # Get the current release name
577+ result = c .run (
578+ f"basename $(readlink { deploy_path } /current)" ,
579+ hide = True
580+ )
581+ release_name = result .stdout .strip () if result else ""
582+
583+ # Backup only the current release
584+ c .run (
585+ f"tar -czf { backup_file } -C { deploy_path } /releases "
586+ f"{ release_name } "
587+ )
588+ logger .info (f"Backup created for release: { release_name } " )
559589 except DeployerException as e :
560590 logger .warning (f"Backup creation failed: { e } " )
561591 return
562592
563593 # Delete older backups if exceeding max_backups
564594 try :
565- result = c .run (f"ls -1t { backup_path } /{ site_name } _*.tar.gz" ,
566- hide = True , warn = True )
595+ result = c .run (
596+ f"ls -1t { backup_path } /{ site_name } _*.tar.gz" ,
597+ hide = True , warn = True
598+ )
567599
568600 # Initialize files as an empty list by default
569601 files = []
0 commit comments