diff --git a/roles/sigvild-gallery/tasks/restore.yml b/roles/sigvild-gallery/tasks/restore.yml index f87c9d1..9053013 100644 --- a/roles/sigvild-gallery/tasks/restore.yml +++ b/roles/sigvild-gallery/tasks/restore.yml @@ -17,7 +17,7 @@ - name: Display found backup files debug: - msg: "Found backup: {{ item.path }} ({{ (item.size / 1024 / 1024) | round(2) }}MB, {{ item.mtime | to_datetime }})" + msg: "Found backup: {{ item.path }} ({{ (item.size / 1024 / 1024) | round(2) }}MB, {{ '%Y-%m-%d %H:%M:%S' | strftime(item.mtime | int) }})" loop: "{{ backup_files.files | sort(attribute='mtime') }}" when: backup_files.files | length > 0 @@ -33,6 +33,15 @@ - existing_data.stat.exists - backup_files.files | length > 0 +- name: Skip restore due to existing data + debug: + msg: + - "🛡️ SAFETY: Restore skipped to protect existing data" + - "Remove {{ sigvild_gallery_data_dir }}/data.db manually to enable restore" + when: + - existing_data.stat.exists + - backup_files.files | length > 0 + - name: Restore from latest backup block: - name: Get latest backup file @@ -45,12 +54,22 @@ - "Restoring from latest backup: {{ latest_backup | basename }}" - "Target directory: {{ sigvild_gallery_data_dir }}" + - name: Check if sigvild-gallery service exists + stat: + path: /etc/systemd/system/sigvild-gallery.service + register: sigvild_service_file + - name: Stop sigvild-gallery service before restoration systemd: name: sigvild-gallery state: stopped register: service_stopped_for_restore - ignore_errors: true # Service might not exist on fresh deployment + when: sigvild_service_file.stat.exists + ignore_errors: true + + - name: Display service stop status + debug: + msg: "{{ 'Service stopped for restoration' if sigvild_service_file.stat.exists else 'Service does not exist yet - skipping stop' }}" - name: Upload backup to remote server copy: @@ -116,11 +135,13 @@ - "Restored data size: {{ restored_size.stdout }}" - "Location: {{ sigvild_gallery_data_dir }}" - when: backup_files.files | length > 0 + when: + - backup_files.files | length > 0 + - not existing_data.stat.exists - name: No backup available message debug: msg: - "ℹ️ No backup files found - starting with fresh installation" - "Data directory will be created empty: {{ sigvild_gallery_data_dir }}" - when: backup_files.files | length == 0 \ No newline at end of file + when: backup_files.files | length == 0 diff --git a/roles/sigvild-gallery/templates/sigvild-gallery.service.j2 b/roles/sigvild-gallery/templates/sigvild-gallery.service.j2 index b93be3e..f735b12 100644 --- a/roles/sigvild-gallery/templates/sigvild-gallery.service.j2 +++ b/roles/sigvild-gallery/templates/sigvild-gallery.service.j2 @@ -10,7 +10,7 @@ WorkingDirectory={{ sigvild_gallery_home }} ExecStart={{ sigvild_gallery_binary }} serve --http={{ sigvild_gallery_host }}:{{ sigvild_gallery_port }} # Environment variables -Environment="SIGVILD_ENVIRONMENT"="production" # Lets caddy handle CORS +Environment="SIGVILD_ENVIRONMENT"="production" Environment="HOST_USERNAME={{ sigvild_gallery_host_username }}" Environment="HOST_PASSWORD={{ sigvild_gallery_host_password }}" Environment="HOST_DISPLAY_NAME=Wedding Host"