HELP ME WITH BATCH THIS

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
hoangpuon1983
Posts: 6
Joined: 17 Jan 2018 23:24

HELP ME WITH BATCH THIS

#1 Post by hoangpuon1983 » 17 Jan 2018 23:31

I want to backup file of yesterday. I search on internet. I have a batch but it is not run zip. Please people help me thank you verry much.


@echo off

cls

::BACKUP SQL
for /f "delims=" %%a in ('wmic OS Get localdatetime ^| find "."') do set dt=%%a
set YYYY=%dt:~0,4%
set MM=%dt:~4,2%
set DD=%dt:~6,2%
set HH=%dt:~8,2%
set Min=%dt:~10,2%
set Sec=%dt:~12,2%
set date1=%YYYY%-%MM%-%DD%


set day=-1
echo >"%temp%\%~n0.vbs" s=DateAdd("d",%day%,now) : d=weekday(s)
echo>>"%temp%\%~n0.vbs" WScript.Echo year(s)^& right(100+month(s),2)^& right(100+day(s),2)
for /f %%a in ('cscript /nologo "%temp%\%~n0.vbs"') do set "result=%%a"
del "%temp%\%~n0.vbs"
set "YYYY=%result:~0,4%"
set "MM=%result:~4,2%"
set "DD=%result:~6,2%"
set "date2=%yyyy%-%mm%-%dd%"

set "src=C:\Users\Administrator\Desktop\1\"
set "dest=C:\Users\Administrator\Desktop\2\"


echo %date1%
echo %date2%

:: I copy file ok
robocopy %src% %dest% /copyall /maxage:2 /S /ZB /NDL /TEE /NP /R:1 /W:1 /XF

:: but I want to create file zip for backup ????
"C:\Program Files (x86)\7-Zip\7za.exe" a -tzip -p1@ "%dest%\%date1%.zip" "%src%\%date2%"

echo Done![*][*][/b]

pause

ShadowThief
Expert
Posts: 1055
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: HELP ME WITH BATCH THIS

#2 Post by ShadowThief » 18 Jan 2018 00:41

7-zip should be displaying some kind of message when it tries to be run. What message are you getting? I'm guessing that it has something to do with either your source or destination paths.

hoangpuon1983
Posts: 6
Joined: 17 Jan 2018 23:24

Re: HELP ME WITH BATCH THIS

#3 Post by hoangpuon1983 » 18 Jan 2018 01:21

Can you help me ?

Link :
https://youtu.be/abmfTmWLF0c

hoangpuon1983
Posts: 6
Joined: 17 Jan 2018 23:24

Re: HELP ME WITH BATCH THIS

#4 Post by hoangpuon1983 » 18 Jan 2018 01:34

I want to write batch backup .

The first
Image

I want to backup file with date yesterday by zip.

But it's compressed files all fill . It isn't backup with yesterday .

I just want in file zip only file of day 17/01/2018

This video : https://youtu.be/abmfTmWLF0c

Hope you can help me. Thanks

SIMMS7400
Posts: 525
Joined: 07 Jan 2016 07:47

Re: HELP ME WITH BATCH THIS

#5 Post by SIMMS7400 » 20 Jan 2018 04:56

I'm Going to assume your source doesn't exist....If it does infact have a date on what you're trying to zip (source) you'll need to formulate a way to grab that dynamically.

Here is one of a few 7ZIP processes I have - I just grabbed the 7zip portion for my script. This should have you get going:

Code: Select all

::-- Set Working Directory as Script Path --::

cd /d %~dp0

::-- Call Environment File --::

CALL _env.cmd

::-- Set Main Intrapath Variables --::

SET "INTRAPATH=%LOGPATH%"
SET "ERRORINTRAPATH=%ERRORPATH%"

::-- Parse Native DOS Command 'Time' --::

FOR /f "tokens=1-2 delims=/:" %%A IN ("%TIME%")   DO ( SET "TIMESTAMP=%%A%%B" )
FOR /f "tokens=* delims= " %%C IN ("%TIMESTAMP%") DO ( SET "TIMESTAMP=%%C")
SET "DATETIME=%date:~-4,4%%date:~-10,2%%date:~-7,2%"

::-- Set Log ^& Error Files --::

SET "LOGFILE=%INTRAPATH%%DATETIME%_%TIMESTAMP%_%~n0.log"
SET "ERRORFILE=%ERRORINTRAPATH%%DATETIME%_%TIMESTAMP%_%~n0.log"

::-- Begin Script Processing --::
ECHO ********************************************************>>%LOGFILE%
ECHO %~n0 Starting at %TIME%                		   	     >>%LOGFILE%
ECHO ********************************************************>>%LOGFILE%

ECHO ********************************************************>>%LOGFILE%
ECHO Execute 7zip Process               	     	         >>%LOGFILE%
ECHO ********************************************************>>%LOGFILE%

SET "ZIP_BIN=C:\Program Files\7-Zip\7z.exe"

SET "LIST="ASCEND","GPT","RDDATAMART","TACT","TEMPO","TM1","TREX","FTECP","RDRPT","IMPORT","NTScripts","AWS""

FOR %%D IN ( %LIST:,= % ) DO (
	
	SET "SKIP="
		IF "%%~D"=="NTScripts" (
			CALL "%ZIP_BIN%" a -tzip "%ARCHIVEPATH%\UTIL_Archives_%DATETIME%.zip" "%SCRIPTPATH:~0,-1%"
			SET "SKIP=1"
		)
		IF "%%~D"=="AWS" (
			CALL "%ZIP_BIN%" a -tzip "%ARCHIVEPATH%\UTIL_Archives_%DATETIME%.zip" "C:\Users\servicehyperion\.aws"
			SET "SKIP=1"
		)
	IF NOT DEFINED SKIP CALL "%ZIP_BIN%" a -tzip "%ARCHIVEPATH%\UTIL_Archives_%DATETIME%.zip" "%ARCHIVEPATH%%%~D"
)

ShadowThief
Expert
Posts: 1055
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: HELP ME WITH BATCH THIS

#6 Post by ShadowThief » 20 Jan 2018 09:17

I'm not entirely sure what I'm supposed to be looking at in your video. You are very clearly able to create a zip file that contains four files in it.

hoangpuon1983
Posts: 6
Joined: 17 Jan 2018 23:24

Re: HELP ME WITH BATCH THIS

#7 Post by hoangpuon1983 » 22 Jan 2018 01:37

Thank you very much. Thank you everyone help me.

But it not run.

The first, A folder contains files :
Source : C:\Users\Administrator\Desktop\1
Dest : C:\Users\Administrator\Desktop\2

Name Date modified
18a 18/01/2018
18b 18/01/2018
21 21/01/2018
21b 21/01/2018
21c 21/01/2018

Today is 22/01/2018


I have batch script :

@echo off

cls

::BACKUP SQL
for /f "delims=" %%a in ('wmic OS Get localdatetime ^| find "."') do set dt=%%a
set YYYY=%dt:~0,4%
set MM=%dt:~4,2%
set DD=%dt:~6,2%
set HH=%dt:~8,2%
set Min=%dt:~10,2%
set Sec=%dt:~12,2%
set date=%DD%-%MM%-%YYYY%

set "src=C:\Users\Administrator\Desktop\1"
set "dest=C:\Users\Administrator\Desktop\2\%date%"


robocopy %src% %dest% /copyall /MAXage:2 /S /ZB /NDL /TEE /NP /R:2 /W:2 /XF


:end
pause

Then i run batch script. It create foler 22-01-2018 and copy files date 21/01/2018 true. However, i want it after it create folder 22-01-2018 and in folder 22-01-2018 is files date 21/01/2018 compress folder zip ---> ( folder 22/01/2018.zip)

But i don't know writer next batch script

Hope you help me. Thank you very much. :D

Link video : https://youtu.be/HjAc5WCmEQA

Post Reply