Advertisement
J2897

Ditto Backups

Jul 24th, 2024 (edited)
520
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 2.04 KB | None | 0 0
  1. @echo off
  2. setlocal
  3.  
  4. REM This is a backup script I've designed solely for use with the Ditto clipboard manager.
  5.  
  6. :: Instructions:
  7. :: To schedule this script to run monthly using the Windows Task Scheduler:
  8. :: 1. Open Task Scheduler.
  9. :: 2. Click "Create Basic Task..." in the Actions pane.
  10. :: 3. Name the task and provide a description, then click "Next".
  11. :: 4. Select "Monthly" and click "Next".
  12. :: 5. Set the desired start date_time and time, choose all of the months and the day, then click "Next".
  13. :: 6. Select "Start a program" and click "Next".
  14. :: 7. Click "Browse..." and select this script file.
  15. :: 8. Click "Next" and then "Finish".
  16.  
  17. :: Paths
  18. set "DITTO_PATH=C:\Program Files\Ditto\Ditto.exe"
  19. set "DITTO_DB_PATH=%USERPROFILE%\AppData\Roaming\Ditto\Ditto.db"
  20. set "BACKUP_PATH=X:\Storage\Ditto"
  21. set "ZIP_EXE=C:\Program Files\7-Zip\7z.exe"
  22. set "PASSWORD=password123" || REM Set the 7-Zip password to encrypt the backups
  23.  
  24. :: Disconnect and exit Ditto using command line
  25. "%DITTO_PATH%" /Disconnect
  26. timeout /t 3 /nobreak >nul
  27. "%DITTO_PATH%" /Exit
  28.  
  29. :: Alert the user
  30. echo Ditto backup initiated. Do not use. This will only take a few seconds.
  31. timeout /t 10
  32.  
  33. :: Close Ditto
  34. :waitloop
  35. taskkill /im Ditto.exe
  36. timeout /t 1 /nobreak >nul
  37. tasklist /fi "imagename eq Ditto.exe" | find /i "Ditto.exe" >nul
  38. if not errorlevel 1 (
  39.     goto waitloop
  40. )
  41.  
  42. :: Get the current date and time in YYYY-MM-DD_HH-MM format
  43. for /f "tokens=2 delims==." %%I in ('wmic OS Get localdatetime /value') do set DT=%%I
  44. set "DATE_TIME=%DT:~0,4%-%DT:~4,2%-%DT:~6,2%_%DT:~8,2%-%DT:~10,2%"
  45.  
  46. :: Backup Ditto database file with password
  47. "%ZIP_EXE%" a -tzip -p%PASSWORD% "%BACKUP_PATH%\%DATE_TIME%.zip" "%DITTO_DB_PATH%"
  48.  
  49. :: Check if backup was successful
  50. if exist "%BACKUP_PATH%\%DATE_TIME%.zip" (
  51.    :: Delete the original database file
  52.     del "%DITTO_DB_PATH%"
  53.     timeout /t 10
  54. ) else (
  55.     echo Backup failed, original file not deleted.
  56.     pause
  57.     exit /b 1
  58. )
  59.  
  60. :: Reopen Ditto
  61. start "" "%DITTO_PATH%"
  62. timeout /t 3 /nobreak >nul
  63. "%DITTO_PATH%" /Connect
  64.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement