@echo off
:: (::< COLONS define lines of COMMENT/EXPLANATIONS)
:: 'echo-lines' are explanations and can be removed 
:: but the only '@echo off'-line
:: If your folders have "unusual" characters try to use correct language for  "setlocal" 
:: for setlocal, see www.ss64.com
:: script location https://forum.vivaldi.net/topic/51704/guide-vivaldi-back-up-extra-steps/45

:: --- CONFIGURATION: 
:: 1. Change SOURCE to match your local Vivaldi source folder. 
:: 2. Decide location of backups 
:: 3. "Base" or root name can be whatever you like (point is: the script will place a counter cifer at the end)
:: 4. A suggestion is to use Vivaldi version number as part of basis folder name so that when you later upgrade Vivaldi change the '7.7.67'-part to '7.8.5' in the script--->>
:: 5. Save scipt as "VivaldiBackup.bat" or "Something.bat" 
:: 6. Make a shortcut to it and give Properties = Run As Admin
:: 7. Thats it. Now double clik your bat-shortcut and let the safe fun begin!

:: Change these 3 lines below first!
set "source=%localappdata%\Vivaldi\User Data"
set "destinationBase=%documents%\Vivaldi-backup"
set "baseName=Vivaldi-%date%"

:: CODE BEGINS
:: -----------------------------------
echo Backup script for Your Vivaldi Installation Standalone (Only)
echo.
echo Author: This script wants to be Free
echo Location @ Vivaldi Forum:
echo https://forum.vivaldi.net/topic/51704/guide-vivaldi-back-up-extra-steps/45

setlocal
chcp 65001 >nul
echo Codepage set to UTF-8 (65001)
echo.
echo Script will now run silently...

:: --- SCRIPT FOR UNIQUE FOLDER NAMING---
set "counter=1"
:checkExistence
set "newFolderName=%baseName%-%counter%"
if exist "%destinationBase%\%newFolderName%" (
    set /a counter+=1
    goto checkExistence
)

:: --- SCRIPT IS CREATING A NEW COUNTED DESTINATION FOLDER ---
set "destination=%destinationBase%\%newFolderName%"
mkdir "%destination%"

:: --- SCIPT CALLS ON ROBOCOPY TO SAVE CONTENTS OF SOURCE FOLDER TO DESTINATION FOLDER ---
robocopy "%source%" "%destination%" /E /NFL /NDL /W:5 ^
/XD *cache* *Crashpad*

echo.
echo ✅ Your Vivaldi backup is finished.
echo You can find it here: 
echo %destination%
endlocal

:: MESSAGE
:: You can REMOVE below command "PAUSE" if no need to view these completion results
pause

:: CODE END