If you are using git bash, (here it is for bash on windows WSL) this script backs up your Opera session and session storage files to a specified directory.
=> Please customize the placeholders before running it.
FIRST
- Create a file where to put your script, for example:
MY_SCRIPT.sh
Then inlcude the code:
#!/bin/bash
TIMESTAMP=$(date +"%Y%m%d_%H%M%S")
# Initialize an array to store issues
issues=()
success=()
# Define source paths with placeholders
SOURCE_BASE="C:/Users/%USERNAME%/AppData/Roaming/Opera Software/Opera Stable/Default"
SOURCE_SESSIONS="$SOURCE_BASE/Sessions"
SOURCE_SESSION_STORAGE="$SOURCE_BASE/Session Storage"
# Define backup destination with placeholder
BACKUP_DIR="D:/%PATH-TO-DESTINATION%/Opera/session saves/$TIMESTAMP"
# Create backup directory
if ! mkdir -p "$BACKUP_DIR"; then
issues+=("Failed to create backup directory.")
else
success+=("Backup directory created successfully.")
fi
# Create session directories
SESSIONS_DIR="$BACKUP_DIR/Sessions"
SESSION_STORAGE_DIR="$BACKUP_DIR/Session_Storage"
if ! mkdir -p "$SESSIONS_DIR"; then
issues+=("Failed to create Sessions directory.")
else
success+=("Sessions directory created successfully.")
fi
if ! mkdir -p "$SESSION_STORAGE_DIR"; then
issues+=("Failed to create Session Storage directory.")
else
success+=("Session Storage directory created successfully.")
fi
# Copy session files
if cp -r "$SOURCE_SESSIONS/"* "$SESSIONS_DIR"; then
success+=("Successfully copied session files to $SESSIONS_DIR")
else
issues+=("Failed to copy session files.")
fi
# Copy session storage files
if cp -r "$SOURCE_SESSION_STORAGE/"* "$SESSION_STORAGE_DIR"; then
success+=("Successfully copied session storage files to $SESSION_STORAGE_DIR")
else
issues+=("Failed to copy session storage files.")
fi
# Set permissions for the script
chmod 400 "%YOUR-PATH%/%MY_SCRIPT%.sh" # Read owner, no write, no execute
if [ $? -eq 0 ]; then
success+=("Permissions set successfully to read only for script and user.")
else
issues+=("Failed to set permissions.")
fi
# Log file creation
LOG_FILE="$BACKUP_DIR/backup_log.log"
# Log issues and successes
if [ ${#issues[@]} -eq 0 ]; then
echo "# No issues reported during backup process." >> "$LOG_FILE"
echo "No issues reported during backup process."
else
echo "# Backup process completed with following issues:" >> "$LOG_FILE"
echo "Backup process completed with issues: see log file for details."
for issue in "${issues[@]}"; do
echo " - $issue" >> "$LOG_FILE"
done
fi
if [ ${#success[@]} -eq 6 ]; then
echo "## Fully completed backup process, success of the following process:" >> "$LOG_FILE"
for success in "${success[@]}"; do
echo " - $success" >> "$LOG_FILE"
done
else
echo "## Backup process incomplete, success of the following process:" >> "$LOG_FILE"
echo "Backup process incomplete, see log file for details."
if [ ${#success[@]} -gt 0 ]; then
for success in "${success[@]}"; do
echo " - $success" >> "$LOG_FILE"
done
else
echo "## Backup process incomplete, no success to list!" >> "$LOG_FILE"
fi
fi
# Final messages
echo "Backup process completed to:"
echo "$BACKUP_DIR."
echo "See backup_log file in created folder for details about issues or success."
echo "Opening directory..."
explorer.exe "$(cygpath -w "$BACKUP_DIR")"
echo "Goodbye!"
Notes:
- Replace %USERNAME% with your Windows username.
- Replace %PATH-TO-DESTINATION% with your desired backup destination path.
- Ensure you have the necessary permissions to run the script.
(Use on the MY_SCRIPT.sh file that contains the code:
chmod +wx MY_SCRIPT.sh
).
Then, run with this command:
./MY_SCRIPT.sh
You should see the completion messages in the terminal and explorer should open in the created folder.
Edit the code if you want to open folder differently or not at all and the log file created.