# Operational Behaviour

This section explains how the Instance Migrator behaves during and after execution.

## State Management and Persistence

Instance Migrator stores migration state in persistent state files so it can support resume behaviour and continuous polling.

- **State Directory**: Specifies the location of persistent state files. The default location is `./state/`

- **Migration Progress Tracking**: Tracks the last completed asset timestamp for each repository.

- **Polling State**: Tracks next query timestamps for efficient incremental polling

- **Auto-Resume**: Automatically resumes from last known state on restart

- **Persistent State Updates**: Saves state changes every 5 seconds for reliability

## Transfer Complete Notifications

Instance migrator can automatically send notifications to the target Nexus instance when repositories complete migration. This provides visibility into migration progress and integrates with the target instance's notification system.

Notifications are sent in the following two scenarios

- When the migration for each individual repository is complete

- In continuous polling mode, periodic notifications are sent based on the configured interval (default: every 24 hours)

The following codeblock describes the notification configuration options

**Interactive Shell Commands:**

- View current notification settings:

```
config show
```

- Enable or disable notifications:

```
config set transfer-complete-notification-enabled true
```

- Set notification interval (minimum 1 hour):

```
config set transfer-complete-notification-interval-hours 12
```

- Manually send notification for a specific repository (uses current metrics):

```
notify repository maven-central
```

- Manually send overall completion notification (aggregates all repositories):

```
notify overall
```

## Security

The migrator implements several security measures to protect sensitive credentials. Some of them are given below:

- #### Password Masking in Console Output:

When setting passwords via config set `source-nexus-password` or config set `target-nexus-password`, the password value is never displayed in the console output. The command returns set `source-nexus-password` to: `****` instead of showing the actual password

- #### Log File Protection:

Intercepts and blocks any log entries containing password-related commands as the config show command masks password values in the output. History commands do not store or display any entries, file-based history is not persisted and in-memory history is disabled.

- #### Command History Behaviour:

The security configuration disables application-level history. Terminal-level history is available as commands may still be recalled with up arrow within the same terminal session. However passwords entered are not saved to any file.

**Note**

The following security configuration in the  `application.properties` enhance security.

```
#Disable command history to prevent password storage
spring.shell.history.enabled=false
spring.shell.command.history.enabled=false
```

Additionally, the `ShellSecurityConfig` provides

- Custom `DisabledHistory` implementation that discards all commands

- Prevents up arrow from recalling previous commands

- Ensures no history file (`spring-shell.log`) is created

## Logging

Instance Migrator writes standard application logs and separate asset transfer logs during migration. The main application log records overall migrator activity. Separate asset transfer logs record successful and failed asset transfers. Logging levels and log file rotation are configurable. Passwords are masked in log output.

The migrator provides the following log outputs:

- **Application Log**

It records overall migrator activity and runtime information. By default, this log is written to `logs/nexus-migrator.log`.

- **Successful Asset Transfer Log**

It records successfully migrated assets and provides an audit trail for migration progress. By default, this log is written to `logs/asset-transfers.log`

- **Failed Asset Transfer Log**

It records asset transfer failures to help with troubleshooting and retry analysis. By default, this log is written to `logs/failed-asset-transfers.log`

- **Configurable Log Levels**

Supports configurable logging levels for the application and migrator components.

- **Log Rotation**

Supports configurable log file size limits and retention history.

Use the following settings to configure the main application log:

```
# Log file configuration
logging.file.name=logs/nexus-migrator.log
logging.file.max-size=10MB
logging.file.max-history=30

# Log levels
logging.level.root=INFO
logging.level.com.sonatype.nexus.tools=DEBUG
```

Use the application log for overall migration activity. Use the asset transfer logs when you need to verify migrated assets or investigate transfer failures.
