PowerShell scripts for fast, reliable user data backup and restore using Robocopy with recovery features and merge capabilities.
- Interactive prompts for user selection, storage device, and backup folder
- Smart filtering - backs up user data including OneDrive synced folders
- PST exclusion - automatically excludes large Outlook PST files
- Resume functionality - continues interrupted backups with exact file-level tracking
- Progress tracking - visual progress bar with ETA and real-time status
- Time estimation - calculates estimated backup time based on data size
- Multi-threaded copying - uses Robocopy with optimized thread count for reliability
- Detailed logging - creates backup_log.txt with full operation details and progress markers
- Enhanced error handling - detailed exit code interpretation and retry logic
- Target user selection - choose which user to restore data to
- Backup discovery - automatically finds backup folders on storage devices
- Single restore - restore one backup to a user account
- Merge functionality - combine multiple backups into one user account
- Smart folder mapping - correctly maps OneDrive folders back to OneDrive locations
- Size estimation - calculates restore size and time before starting
- Progress tracking - visual progress bar with ETA and real-time status
- Enhanced conflict resolution - detailed file comparison with smart merging options
powershell -Command "iwr -useb 'https://raw.githubusercontent.com/iEdgir01/windows_tools/main/UserBackup.ps1' | iex"powershell -Command "iwr -useb 'https://raw.githubusercontent.com/iEdgir01/windows_tools/main/UserRestore.ps1' | iex".\UserBackup.ps1 # User backup with resume functionality.\UserRestore.ps1 # Restore with merge capabilitiesYou can skip prompts by providing parameters:
# User backup
.\UserBackup.ps1 -Username "JohnDoe" -BackupLocation "E:" -BackupFolder "Backup_2024"# Interactive restore (asks about conflicts)
.\UserRestore.ps1 -TargetUser "JohnDoe" -SourceLocation "E:" -BackupFolders @("Backup_2024", "Backup_2023")
# Automated restore with conflict resolution
.\UserRestore.ps1 -TargetUser "JohnDoe" -SourceLocation "E:" -ConflictResolution "IfNewer"ConflictResolution Options:
"Ask"- Interactive prompts for each conflict (default)"Skip"- Keep existing files, skip conflicts"Overwrite"- Replace all conflicting files"IfNewer"- Only overwrite if new file is more recent
- Desktop
- Downloads
- Documents
- Pictures
- Videos
- Music
- OneDrive\Desktop
- OneDrive\Documents
- OneDrive\Pictures
- OneDrive\Videos
- OneDrive\Music
- PST files - Outlook data files (*.pst)
- Application data (AppData)
- System files
- Shortcuts
- Temporary files
- Program files
/MIR- Mirror directory (complete copy, creates dirs, deletes extras)/COPY:DAT- Copy data, attributes, and timestamps/XF *.pst- Exclude PST files/MT:8- Multi-threaded copying (8 threads for stability)/R:5- Retry failed copies 5 times/W:30- Wait 30 seconds between retries/SKIP:SL- Skip symbolic links to avoid issues
/E- Copy subdirectories including empty ones/COPY:DAT- Copy data, attributes, and timestamps/MT:8- Multi-threaded copying (8 threads for restore)/R:5- Retry failed copies 5 times/W:30- Wait 30 seconds between retries/SKIP:SL- Skip symbolic links to avoid issues/IS- Include Same files (used in merge operations for consistency)/IT- Include Tweaked files (used in merge operations for overwrites)- Smart merge handling with explicit conflict resolution
The restore script provides flexible options for data recovery:
- Target User Selection - Choose which user account to restore data to
- Storage Device Detection - Automatically detects and lists available drives
- Backup Discovery - Scans for folders containing backup data structure
- Restore Options:
- Single Restore - Restore one backup folder to the target user
- Merge Multiple - Combine data from multiple backup folders into one user account
- Smart Folder Mapping:
- Standard folders (Desktop, Documents, etc.) →
C:\Users\[TargetUser]\[Folder] - OneDrive folders →
C:\Users\[TargetUser]\OneDrive\[Folder]
- Standard folders (Desktop, Documents, etc.) →
- Progress Tracking - Real-time status updates and completion reporting
When merging multiple backups, the script processes them in the order selected:
- First backup - Copied normally to the target user
- Subsequent backups - Conflicts are detected and user chooses resolution:
When file conflicts are detected, you choose how to handle them:
- Skip conflicts - Keep existing files, don't overwrite anything
- Overwrite all - Replace all conflicting files with new versions
- Keep newer files only - Smart date-based replacement (newer files win)
- Review individually - Decide file-by-file with enhanced details:
- Enhanced date display: Shows exact timestamps and file age
- Clear newer indicator: Highlights which file is more recent and by how much
- Multiple options per file: (O)verwrite, (S)kip, Keep (N)ewer, (A)bort, or apply to (A)ll
- Apply to all remaining: After reviewing one conflict, apply the same decision to all remaining conflicts
Conflict: Documents\ProjectPlan.docx
Existing: 2,450,123 bytes
Last modified: 2024-01-15 09:30:22 (25 days ago)
New: 2,551,890 bytes
Last modified: 2024-01-20 14:22:15 (20 days ago)
→ New file is NEWER by 5 days, 4 hours
(O)verwrite, (S)kip, Keep (N)ewer, (A)bort folder, or apply to (A)ll remaining?
Benefits of Enhanced Resolution:
- Safe merging - No accidental overwrites of important files
- Informed decisions - See exact dates, file sizes, and age comparisons
- Flexible handling - Different strategies per backup or folder
- Batch decisions - Apply same choice to multiple conflicts
- Smart newer detection - Automatically identifies which file is more recent
- Abort option - Stop if conflicts are too complex to resolve
The backup script includes advanced resume capabilities:
- Detects incomplete backups on startup
- Analyzes existing log files to determine progress
- Offers to continue from where backup was interrupted
- Tracks individual files copied for each folder
- Creates dynamic exclusion lists for already-copied files
- Avoids redundant file copying during resume operations
- Saves progress markers to log files in JSON format
- Maintains accurate progress tracking across resume sessions
- Displays clear status of missing vs incomplete folders
- Windows PowerShell 5.0 or later
- Administrative privileges may be required for some user profiles
- Sufficient free space on backup destination (for backup operations)
- Sufficient free space on target user profile (for restore operations)