Last active
January 29, 2017 07:17
-
-
Save dobrivoje/3c2210af7b814f880d5709d209a11827 to your computer and use it in GitHub Desktop.
Googlesync Windows batch script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'version 29.1.2017 8:13 | |
'NOTICE : | |
'Nor files neither folder should contain "space" in their names | |
'since the script will ommit characters after the first space occurence in it's name | |
'in "%%~nF.7z" | |
'7zip execution folder | |
set comdir=C:\Program Files\7-Zip | |
'First backup folder | |
set dir1=K:\Baze\temp | |
'Second backup folder | |
'set dir2=K:\Users\temp | |
set temp=K:\temp | |
'Output directory | |
set outdir=D:\Backup\GDrive\SQL Server | |
'Log file location | |
set log="%outdir%\log.log" | |
echo ------------------ >> %log% | |
echo pocetak >> %log% | |
echo %date% - %time% >> %log% | |
echo ------------------ >> %log% | |
'Ensure that googledrivesync.exe is not active process | |
echo [%date% - %time%] Stop GDrive servisa... >> %log% | |
taskkill /f /im googledrivesync.exe >> %log% | |
'Start googledrivesync.exe | |
echo [%date% - %time%] Start GDrive servisa... >> %log% | |
start /B "" "C:\Program Files (x86)\Google\Drive\googledrivesync.exe" | |
'since gdrive service need som time to start, wait for 20 seconds.. | |
'timeout 20 | |
'make archive folder which name is current date | |
'set nazivArhive=%date:~-10,2%"-"%date:~7,2%"-"%date:~-4,4% | |
'make archive folder which name is current date | |
'in the form : dd-MM-yyyy, npr. 27-01-2017 | |
set nazivArhive=%date:~-7,2%"-"%date:~4,2%"-"%date:~-4,4% | |
'final output directory path | |
set finalOutDir="%outdir%\%nazivArhive%" | |
mkdir %finalOutDir% | |
'iterate through backup directory (or directories) | |
'example: | |
'FOR %%F IN ("%dir1%\*" "%dir2%\*" "%even_other_dir%\*") DO ( | |
FOR %%F IN ("%dir1%\*" ) DO ( | |
echo [%date% - %time%] poc kompresije : ["%%F"] >> %log% | |
"%comdir%\7z.exe" a -mx9 -mmt -t7z "%temp%\%%~nF.7z" "%%F" | |
rem give "7z.exe" process the lowest priority : | |
rem command below not working well. TODO ! | |
wmic process where name="7z.exe" CALL setpriority "idle" | |
rem move from temp to final output directory | |
move "%temp%\%%~nF.7z" %finalOutDir% | |
echo [%date% - %time%] kraj kompresije : ["%%F"] >> %log% | |
echo. | |
echo [%date% - %time%] brisanje dir : ["%%i"] >> %log% | |
rem deletion isn't working this way below. analiz why. TODO #2 | |
rem del "%%F" /Q /S >> %log% | |
) | |
'since deletion above not working, delete all files from temp folder the other way | |
del "%dir1%\*.*" /S /Q >> %log% | |
'Due to various reasons, sync may take 300 sec (~5 minutes), so wait some time | |
'for GDrive sync to complete, and then turn it off | |
echo ------------------ >> %log% | |
timeout 600 >> %log% | |
echo ------------------ >> %log% | |
echo [%date% - %time%] Stop GDrive servisa... >> %log% | |
taskkill /f /im googledrivesync.exe >> %log% | |
echo ------------------ >> %log% | |
echo kraj >> %log% | |
echo %date% - %time% >> %log% | |
echo ------------------ >> %log% |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment