92 lines
3.0 KiB
Bash
92 lines
3.0 KiB
Bash
#!/bin/bash
|
|
|
|
# ---
|
|
# Configuration ---
|
|
# ---
|
|
LOG_FILE="logs/02_file_migration.log"
|
|
DRY_RUN=""
|
|
SOURCE_HOME="/home/sam" # This should be the path where your old home is mounted
|
|
TARGET_STAGING="/mnt/ubuntu_storage_3TB/migration_staging" # As per the guide
|
|
|
|
# Check for --dry-run flag
|
|
if [ "$1" == "--dry-run" ]; then
|
|
DRY_RUN="--dry-run"
|
|
echo "---
|
|
PERFORMING DRY RUN ---" | tee -a "$LOG_FILE"
|
|
fi
|
|
|
|
# Safety check for root user
|
|
if [ "$(id -u)" -eq 0 ] && [ "$2" != "--allow-root" ]; then
|
|
echo "Running as root is not recommended. Use --allow-root to override."
|
|
exit 1
|
|
fi
|
|
|
|
# ---
|
|
# Helper Functions ---
|
|
# ---
|
|
log() {
|
|
echo "$1" | tee -a "$LOG_FILE"
|
|
}
|
|
|
|
run_rsync() {
|
|
log "------------------------------------------------------------------------"
|
|
log "Syncing $1..."
|
|
# The --info=progress2 flag gives a cleaner total progress indicator.
|
|
# The --exclude='/data' is critical to not re-copy existing data.
|
|
rsync -avh --info=progress2 $DRY_RUN --exclude='/data' "$2" "$3"
|
|
log "Finished syncing $1."
|
|
log "------------------------------------------------------------------------"
|
|
}
|
|
|
|
|
|
# ---
|
|
# Main Execution ---
|
|
# ---
|
|
# Initialize log file
|
|
echo "File Migration Log - $(date)" > "$LOG_FILE"
|
|
echo "----------------------------------------------------" >> "$LOG_FILE"
|
|
|
|
if [ -n "$DRY_RUN" ]; then
|
|
log "Dry run mode enabled. No files will be changed."
|
|
fi
|
|
|
|
log "Source directory: $SOURCE_HOME"
|
|
log "Target staging directory: $TARGET_STAGING"
|
|
|
|
# Check if source directory exists
|
|
if [ ! -d "$SOURCE_HOME" ]; then
|
|
log "ERROR: Source directory $SOURCE_HOME does not exist. Mount your old home directory and try again."
|
|
exit 1
|
|
fi
|
|
|
|
# Create target directory
|
|
log "Creating target staging directory (if it doesn\'t exist)..."
|
|
if [ -z "$DRY_RUN" ]; then
|
|
mkdir -p "$TARGET_STAGING"
|
|
fi
|
|
|
|
# ---
|
|
# Migration Commands ---
|
|
# ---
|
|
# These commands will copy your main user folders from your old Ubuntu home
|
|
# into the staging area. The structure is kept simple for later organization.
|
|
# Note the trailing slash on the source to copy the *contents* of the directory.
|
|
|
|
run_rsync "Documents" "${SOURCE_HOME}/Documents/" "${TARGET_STAGING}/Documents/"
|
|
run_rsync "Pictures" "${SOURCE_HOME}/Pictures/" "${TARGET_STAGING}/Pictures/"
|
|
run_rsync "Music" "${SOURCE_HOME}/Music/" "${TARGET_STAGING}/Music/"
|
|
run_rsync "Videos" "${SOURCE_HOME}/Videos/" "${TARGET_STAGING}/Videos/"
|
|
run_rsync "Desktop" "${SOURCE_HOME}/Desktop/" "${TARGET_STAGING}/Desktop/"
|
|
run_rsync "Downloads" "${SOURCE_HOME}/Downloads/" "${TARGET_STAGING}/Downloads/"
|
|
run_rsync "Dotfiles" "${SOURCE_HOME}/dotfiles/" "${TARGET_STAGING}/dotfiles/"
|
|
|
|
# Add any other specific project directories you know of here. For example:
|
|
# run_rsync "Arduino Projects" "${SOURCE_HOME}/Arduino/" "${TARGET_STAGING}/Arduino/"
|
|
|
|
log "\n"
|
|
log "---
|
|
File migration script finished. ---"
|
|
log "Review the output above. If everything looks correct, you can run the script"
|
|
log "again without the --dry-run flag to perform the actual file copy."
|
|
log "The log has been saved to $LOG_FILE"
|