Set COMPANY=COMPANY

Rem เปลี่ยนตำแหน่งโปรแกรม
D:
Cd\BdPos

Rem ข้อมูลที่ทำงาน
Set DATA_FOLDER=D:\BdPos\
REM Set DATA_FOLDER=M:\

Rem โปรแกรมที่ทำงาน
Set PROG_FOLDER=D:\BdPos\


Rem =========
Set HARD_FOLDER=D:\_Datanet\
Set CLOUD_DRIVE=E:\_Cloud\%COMPANY%\
Set FLASH_DRIVE=E:\


for /f "tokens=1,2,3,4 delims=/ " %%a in ("%date%") do set wday=%%a&set month=%%b&set day=%%c&set year=%%d
echo.Weekday: %wday%
echo.Month  : %month%
echo.Day    : %day%
echo.Year   : %year%

UtilPok 2 %CLOUD_DRIVE%
UtilPok 2 %CLOUD_DRIVE%Backup
UtilPok 2 %CLOUD_DRIVE%Screen
UtilPok 2 %CLOUD_DRIVE%Screen\History
UtilPok 2 %CLOUD_DRIVE%Txt
UtilPok 2 %CLOUD_DRIVE%Pdf
UtilPok 2 %CLOUD_DRIVE%UyodTeam
UtilPok 2 %HARD_FOLDER%
UtilPok 2 %HARD_FOLDER%System
UtilPok 2 %HARD_FOLDER%System\%wday%
UtilPok 2 %HARD_FOLDER%%day%
UtilPok 2 %CLOUD_DRIVE%Backup\System
UtilPok 2 %CLOUD_DRIVE%Backup\System\Original
UtilPok 2 %CLOUD_DRIVE%Backup\_Update
UtilPok 2 %CLOUD_DRIVE%Backup\Share
UtilPok 2 %CLOUD_DRIVE%Backup\%wday%


@Pkzip -u %HARD_FOLDER%Data.Zp     %DATA_FOLDER%Data\*.Dbf
@Pkzip -u %HARD_FOLDER%Data.Zp     %DATA_FOLDER%Data\*.Cdx
@Pkzip -u %HARD_FOLDER%Transac.Zp  %DATA_FOLDER%Transac\*.Dbf
@Pkzip -u %HARD_FOLDER%Transac.Zp  %DATA_FOLDER%Transac\*.Cdx
@Pkzip -u %HARD_FOLDER%BakData.Zp     %DATA_FOLDER%BakData\*.Dbf
@Pkzip -u %HARD_FOLDER%Error.Zp    %DATA_FOLDER%_Error\*.Err
@Pkzip -u %HARD_FOLDER%Data001.Zp  %DATA_FOLDER%Data\001\*.Dbf
@Pkzip -u %HARD_FOLDER%Room.Zp     %DATA_FOLDER%Transac\rooms\*.Dbf
@Pkzip -u %HARD_FOLDER%BackFood.Zp %DATA_FOLDER%backup\FOOD\*.dbf
@Pkzip -u %HARD_FOLDER%Test.Zp     %DATA_FOLDER%Test\*.Dbf
@Pkzip -u %HARD_FOLDER%DataLan.Zp  Backup\Datalan\*.dbf
@Copy %HARD_FOLDER%*.* %HARD_FOLDER%%day%\.

@Pkzip -u %HARD_FOLDER%%COMPANY%.Zpp     %DATA_FOLDER%Data\*.Dbf
@Pkzip -u %HARD_FOLDER%%COMPANY%.Zpp     %DATA_FOLDER%Data\*.Cdx
@Pkzip -u %HARD_FOLDER%%COMPANY%.Zpp     %DATA_FOLDER%Transac\*.Dbf
@Pkzip -u %HARD_FOLDER%%COMPANY%.Zpp     %DATA_FOLDER%Transac\*.Cdx


@Pkzip -u %HARD_FOLDER%System\Master.Zp   %PROG_FOLDER%Master.Exe
@Pkzip -u %HARD_FOLDER%System\Poswin.Zp   %PROG_FOLDER%Poswin.exe
@Pkzip -u %HARD_FOLDER%System\Gl.Zp       %PROG_FOLDER%Gl.exe
@Pkzip -u %HARD_FOLDER%System\Al.Zp       %PROG_FOLDER%Al.exe
@Pkzip -u %HARD_FOLDER%System\Cl.Zp       %PROG_FOLDER%Cl.exe
@Pkzip -u %HARD_FOLDER%System\Bat.Zp      %PROG_FOLDER%*.bat
@Pkzip -u %HARD_FOLDER%System\Bdpos.Zp    %PROG_FOLDER%*.bat
@Pkzip -u %HARD_FOLDER%System\Bdpos.Zp    %PROG_FOLDER%*.dbf
@Pkzip -u %HARD_FOLDER%System\Bdpos.Zp    %PROG_FOLDER%*.cdx
@Pkzip -u %HARD_FOLDER%System\Bdpos.Zp    %PROG_FOLDER%*.Sc?
@Pkzip -u %HARD_FOLDER%System\Bdpos.Zp    %PROG_FOLDER%*.Sp?
@Pkzip -u %HARD_FOLDER%System\Bdpos.Zp    %PROG_FOLDER%*.prg
@Pkzip -u %HARD_FOLDER%System\Bdpos.Zp    %PROG_FOLDER%*.fxp
@Pkzip -u %HARD_FOLDER%System\Bdpos.Zp    %PROG_FOLDER%*.mn?
@Pkzip -u %HARD_FOLDER%System\Bdpos.Zp    %PROG_FOLDER%*.mp?
@Pkzip -u %HARD_FOLDER%System\Report.Zp   %PROG_FOLDER%*.fr?
@Pkzip -u %HARD_FOLDER%System\Report.Zp   %PROG_FOLDER%*.Bmp
@Pkzip -u %HARD_FOLDER%System\Setup.Zp    %PROG_FOLDER%Setup\BdPos\*.*
@Pkzip -u %HARD_FOLDER%System\Dbfrun.Zp   %PROG_FOLDER%Dbfrun\*.Dbf
@Pkzip -u %HARD_FOLDER%System\Dbfrun.Zp   %PROG_FOLDER%Dbfrun\*.Cdx
@Pkzip -u %HARD_FOLDER%System\DirData.Zp  %PROG_FOLDER%DirData\*.Dbf
@Pkzip -u %HARD_FOLDER%System\DirData.Zp  %PROG_FOLDER%DirData\*.Cdx

@Pkzip -u %HARD_FOLDER%System\ReportM.Zp  %DATA_FOLDER%*.fr?
@Pkzip -u %HARD_FOLDER%System\ReportM.Zp  %DATA_FOLDER%*.Bmp
@Pkzip -u %HARD_FOLDER%System\Data2Sc.Zp  %DATA_FOLDER%Data2Sc\*.Dbf
@Pkzip -u %HARD_FOLDER%System\Data2Sc.Zp  %DATA_FOLDER%Data2Sc\*.Cdx
@Pkzip -u %HARD_FOLDER%System\Sc2Pos.Zp   %DATA_FOLDER%Sc2Pos\*.Dbf
@Pkzip -u %HARD_FOLDER%System\Sc2Pos.Zp   %DATA_FOLDER%Sc2Pos\*.Cdx
@Pkzip -u %HARD_FOLDER%System\DataCdx.Zp  %DATA_FOLDER%Data\*.Cdx
@Pkzip -u %HARD_FOLDER%System\TranCdx.Zp  %DATA_FOLDER%Transac\*.Cdx
Copy %PROG_FOLDER%Backup2c.bat   %CLOUD_DRIVE%Backup\System\.
Copy %PROG_FOLDER%Pipop.bat  %CLOUD_DRIVE%Backup\System\.
Copy %HARD_FOLDER%System\*.Zp %HARD_FOLDER%System\%wday%\.

@Pkzip -u Backup\%wday%\Data.Zp     %DATA_FOLDER%Data\*.*
@Pkzip -u Backup\%wday%\Tran.Zp  	%DATA_FOLDER%Transac\*.*
@Pkzip -u Backup\%wday%\Tran.Zp  	%DATA_FOLDER%Transac\*.*
@Pkzip -u Backup\%wday%\Room.Zp 	%DATA_FOLDER%Transac\Rooms\*.*
@Pkzip -u Backup\%wday%\Test.Zp     %DATA_FOLDER%Test\*.*
@Pkzip -u Backup\%wday%\001.Zp	    %DATA_FOLDER%Data\001\*.*


Rem Backup SourceCode
@Pkzip -u Backup\Bdpos.Zp  %PROG_FOLDER%*.Prg
@Pkzip -u Backup\Bdpos.Zp  %PROG_FOLDER%*.fxp
@Pkzip -u Backup\BdPos.Zp  %PROG_FOLDER%*.Scx
@Pkzip -u Backup\BdPos.Zp  %PROG_FOLDER%*.Sct
@Pkzip -u Backup\BdPos.Zp  %PROG_FOLDER%*.Spr
@Pkzip -u Backup\BdPos.Zp  %PROG_FOLDER%*.Spx
@Pkzip -u Backup\BdPos.Zp  %PROG_FOLDER%*.Mnx
@Pkzip -u Backup\BdPos.Zp  %PROG_FOLDER%*.Mnt
@Pkzip -u Backup\BdPos.Zp  %PROG_FOLDER%*.Mpr
@Pkzip -u Backup\BdPos.Zp  %PROG_FOLDER%*.Mpx
@Pkzip -u Backup\BdPos.Zp  %PROG_FOLDER%*.Dbf
@Pkzip -u Backup\BdPos.Zp  %PROG_FOLDER%*.Cdx


Rem Backup Report File
@Pkzip -u Backup\BdPos.Zp  %DATA_FOLDER%*.Fr?
@Pkzip -u Backup\BdPos.Zp  %PROG_FOLDER%*.Bmp
@Pkzip -u Backup\BdPos.Zp  %PROG_FOLDER%*.Exe
@Pkzip -u Backup\BdPos.Zp  %PROG_FOLDER%*.Bat

If Not Exist c:\windows\pkzip.exe     Copy \BdPos\Pk*.Exe  c:\windows\.
If Not Exist c:\windows\Foxw2600.esl  Copy \BdPos\*.es?    c:\windows\.
If Not Exist %windir%\pkzip.exe       Copy R:\BdPos\Pk*.Exe  %windir%\.
If Not Exist %windir%\Foxw2600.esl    Copy R:\BdPos\*.es?    %windir%\.


Rem Temp From M: To C:
Rem @If Exist M:\Data\FileHave.Dir Pkunzip -o Backup\%wday%\Data.Zp     Datatemp
Rem @If Exist M:\Data\FileHave.Dir Pkunzip -o Backup\%wday%\Transac.Zp  Trantemp
Rem @If Exist M:\Data\FileHave.Dir Pkunzip -o Backup\%wday%\DataRoom.Zp Trantemp\Rooms


Rem For Flash Drive 
UtilPok 2  %FLASH_DRIVE%_datanet
UtilPok 2  %FLASH_DRIVE%_datanet\%wday%
UtilPok 2  %FLASH_DRIVE%System
Copy %HARD_FOLDER%System\Dbfrun.Zp %FLASH_DRIVE%_datanet\.
Copy %HARD_FOLDER%Data.Zp %FLASH_DRIVE%_datanet\.    
Copy %HARD_FOLDER%Transac.Zp %FLASH_DRIVE%_datanet\.
Copy %HARD_FOLDER%_error15.zp %FLASH_DRIVE%_datanet\.
Copy %HARD_FOLDER%System\Report.Zp %FLASH_DRIVE%System\.
Copy %HARD_FOLDER%System\Dirdata.Zp %FLASH_DRIVE%System\.
Copy %HARD_FOLDER%Data.Zp 	%FLASH_DRIVE%_datanet\%wday%\.
Copy %HARD_FOLDER%Transac.Zp 	%FLASH_DRIVE%_datanet\%wday%\.


Rem Copy ข้อมูลจาก Harddisk ไป Flash-Drive 
Rem @If Exist %FLASH_DRIVE%BdPos\Data\FILEHAVE.Dir  PkUnzip -o %HARD_FOLDER%Data.Zp %FLASH_DRIVE%BdPos\Data
Rem @If Exist %FLASH_DRIVE%BdPos\Transac\FILEHAVE.Dir  PkUnzip -o %HARD_FOLDER%Transac.Zp %FLASH_DRIVE%BdPos\Transac
Rem @If Exist %FLASH_DRIVE%BdPos\Dbfrun\FILEHAVE.Dir  PkUnzip -o %HARD_FOLDER%Dbfrun.Zp %FLASH_DRIVE%BdPos\Dbfrun
Rem @If Exist %FLASH_DRIVE%BdPos\Data2Sc\FILEHAVE.Dir  PkUnzip -o %HARD_FOLDER%System\Data2Sc.Zp %FLASH_DRIVE%BdPos\Data2Sc
Rem @If Exist %FLASH_DRIVE%BdPos\Sc2Pos\FILEHAVE.Dir  PkUnzip -o %HARD_FOLDER%System\Sc2Pos.Zp %FLASH_DRIVE%BdPos\Sc2Pos
@Cls



Rem Copy ไปที่ G-drive  หรือ DropBOX
Copy %HARD_FOLDER%*.*	 %CLOUD_DRIVE%Backup\.	
Copy %HARD_FOLDER%System\*.*    %CLOUD_DRIVE%Backup\System\.	
Copy %HARD_FOLDER%*.*    	 %CLOUD_DRIVE%Backup\%wday%\.
Copy %HARD_FOLDER%System\*.*   %CLOUD_DRIVE%Backup\%wday%\.

Rem Copy ไฟล์ อัพเดท ต่างๆ
@Pkzip -u %DATA_FOLDER%_update\BdPos \BdPos\Master.exe
@Pkzip -u %DATA_FOLDER%_update\BdPos \BdPos\*.Fr?
@Pkzip -u %DATA_FOLDER%_update\BdPos \BdPos\*.Bmp

Rem ปรับปรุงไฟลอัตโนมัติ 
@If Exist  %CLOUD_DRIVE%Backup\update.zip  Pkunzip -o %CLOUD_DRIVE%Backup\update.zip \BdPos
@If Exist  %CLOUD_DRIVE%Backup\Dbfrun.zip  Pkunzip -o %CLOUD_DRIVE%Backup\Dbfrun.zip \BdPos\Dbfrun
@If Exist  %CLOUD_DRIVE%Backup\Temp.zip  Pkunzip -o %CLOUD_DRIVE%Backup\Temp.zip \BdPos\Temp

@If Exist  %CLOUD_DRIVE%Backup\update.zip  Copy %CLOUD_DRIVE%Backup\update.zip _Update\update.zip
@If Exist  %CLOUD_DRIVE%Backup\update.zip  Copy %CLOUD_DRIVE%Backup\update.zip M:\_Update\update.zip


@If Exist  %CLOUD_DRIVE%Backup\update.zip  Pkunzip -o %CLOUD_DRIVE%Backup\update.zip M:\
@If Exist  %CLOUD_DRIVE%Backup\update.zip  Rename %CLOUD_DRIVE%Backup\update.zip    Up"%day%_%month%_%year%".zip
@If Exist  %CLOUD_DRIVE%Backup\Dbfrun.zip  Rename %CLOUD_DRIVE%Backup\Dbfrun.zip Db"%day%_%month%_%year%".zip
@If Exist  %CLOUD_DRIVE%Backup\Temp.zip  Rename  %CLOUD_DRIVE%Backup\Temp.zip Te"%day%_%month%_%year%".zip

Rem ปรับปรุงโปรแกรมผ่าน PRG 
@If Exist  %CLOUD_DRIVE%Backup\update.prg Foxprox.exe %CLOUD_DRIVE%Backup\update.prg
@If Exist  %CLOUD_DRIVE%Backup\update.prg Rename %CLOUD_DRIVE%Backup\update.prg   Up"%day%_%month%_%year%".prg
@If Exist  %CLOUD_DRIVE%Backup\update.fxp Rename %CLOUD_DRIVE%Backup\update.fxp    Up"%day%_%month%_%year%".fxp

Rem ลบไฟล์อีกครั้งที่ไม่ได้ใช้ 
@If Exist  %CLOUD_DRIVE%Backup\update.zip Del %CLOUD_DRIVE%Backup\update.zip
@If Exist  %CLOUD_DRIVE%Backup\dbfrun.zip Del %CLOUD_DRIVE%Backup\dbfrun.zip
@If Exist  %CLOUD_DRIVE%Backup\temp.zip Del %CLOUD_DRIVE%Backup\temp.zip
@If Exist  %CLOUD_DRIVE%Backup\update.prg Del %CLOUD_DRIVE%Backup\update.prg
@If Exist  %CLOUD_DRIVE%Backup\update.fxp Del %CLOUD_DRIVE%Backup\update.fxp

Rem แยกตามวัน+รอบแคชเชียร์ ต้องมี  D:\_Datanet\ เท่านั้น 
UtilPok2 6 %CLOUD_DRIVE%Backup\%wday%

Rem สำรองครั้งสุดท้าย กรณี Harddisk อาจมีปัญหา 
Rem set _my_datetime=%date%_%time%
Rem set _my_datetime=%_my_datetime: =_%
Rem set _my_datetime=%_my_datetime::=%
Rem set _my_datetime=%_my_datetime:/=_%
Rem set _my_datetime=%_my_datetime:.=_%
Rem UtilPok 2 %CLOUD_DRIVE%Backup\%_my_datetime%
Rem Copy %HARD_FOLDER%Data.Zp %CLOUD_DRIVE%Backup\%_my_datetime%\.    
Rem Copy %HARD_FOLDER%Transac.Zp %CLOUD_DRIVE%Backup\%_my_datetime%\. 
Rem Copy %HARD_FOLDER%Room.Zp %CLOUD_DRIVE%Backup\%_my_datetime%\.    
Rem Copy %HARD_FOLDER%System\Dbfrun.Zp %CLOUD_DRIVE%Backup\%_my_datetime%\. 

Set Time_Boot=30
Rem สำรองทั้ง Folder 
If Not Exist %CLOUD_DRIVE%Backup\System\Original\Original.zp Goto Original
if %day%==15 Goto Original
goto End


:Original
Set Time_Boot=180
Del Temp\*.dbf
Del Temp\*.Cdx
Del Temp\*.Txt
Del Temp\*.Tmp
Del Error\*.Dbf
Del Error\*.Cdx
Del Error\*.Err
Del _Error\*.Dbf
Del _Error\*.Cdx
Del _Error\*.Err
Del DayInOut\*.Dbf
Del DayInOut\*.Cdx
Pkzip -rp %CLOUD_DRIVE%Backup\System\Original\Original.zp %PROG_FOLDER%*.*
goto End


:End
Rem Pause      Press 'Enter' For Restart Windows
Rem Shutdown.exe -r -c "<<< กำลังสำรองขึ้นคลาวด์ ใน %Time_Boot% วินาที โปรดรอสักครู่  >>>" -t %Time_Boot%
Rem Shutdown.exe -s -c "<<< กำลังสำรองขึ้นคลาวด์ ใน %Time_Boot% วินาที โปรดรอสักครู่ >>>" -t %Time_Boot%
Rem UtilPok 6 สำรองข้อมูลสำเร็จ
@Exit






