I have this batch file script to apply 7zip to sub-folders:
FOR /D %%i IN (*.*) DO 7za a -v1G -y -t7z -mx=3 "d:\backuptemp\tools\%%i.7za" "%%i\"
If I run this from within the "tools" folder, it backups up all of the sub-folders within "tools" and puts them in "backuptemp\tools" as 7zip archives.
What I want to do is be able to run this from outside the tools folder, however when I use the following code:
FOR /D %%i IN (d:\tools\*.*) DO 7za a -v1G -y -t7z -mx=3 "d:\backuptemp\tools\%%i.7za" "%%i\"
It tries to create a folder called d:\backuptemp\d:\tools\%nameoffolder%.7za and fails saying the filename syntax is incorrect.
What do I need to change in the syntax to be able to use this batch file outside of the "tools" folder?
Also, if possible I'd like to be able to append a date to the end of the file name. Let's say I have a folder called "Patches" within "tools", how do I make it so the archive will be "Patches_20140207.7za"?
This change should help:
The first four lines of this code will give you reliable YY DD MM YYYY HH Min Sec variables in XP Pro and higher.
#echo off
for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
set "YY=%dt:~2,2%" & 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 "datestamp=%YYYY%%MM%%DD%" & set "timestamp=%HH%%Min%%Sec%"
set "fullstamp=%YYYY%-%MM%-%DD%_%HH%-%Min%-%Sec%"
FOR /D %%i IN (d:\tools\*.*) DO 7za a -v1G -y -t7z -mx=3 "d:\backuptemp\tools\%%~nxi_%datestamp%.7za" "%%i\"
Related
I am having a ROBOCOPY script file which looks like the following:
#echo off
for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
set "YY=%dt:~2,2%" & 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 "datestamp=%HH%-%Min%-%Sec%_%DD%.%MM%.%YYYY%"
robocopy C:\xampp.new\htdocs D:\Backups\Registify.net\%datestamp% /MIR /s /XD dirs PROJECTS /mot:5
It just sets through the variable 'datestamp' the current date and time and uses it as the name of the through it created backup. Since I have more than 1 project and always changing the file structure of the source folder, I want to save the project name in a text file into the source folder, read that out through ROBOCOPY and prepend it to the destinated backup name.
The text file would look like this and is saved unter backup.name.txt in every project's folder e.g.:
meintatenreich
while the backup name should look like this in the end:
meintatenreich_20-47-21_13.10.2018
How to copy only modified & new files from one folder to new location?
the destination folder should be created by current date and time. While copying files, the folder structure should be created automatically.
I know there are many similar questions already answered, but here I want to copy only modified and new files to a folder.
I tried below given solution, but it's not working:
#echo off
for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
set "YY=%dt:~2,2%" & 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 "current_date=%YYYY%-%MM%-%DD%_%HH%-%Min%-%Sec%"
robocopy "D:\source" "d:\%current_date%" /MIR > d:\backup.log
In Windows 7, I want to mkdir named current date if the current date is 2014-09-14, and the folder is named 2014-09-14. So I write a bat file like this:
#echo off
set /A current_date = date /t
mkdir %current_date%
But it doesn't effective. Could someone give me some advice? Thanks a lot!
This should create the folder:
The first four lines of this code will give you reliable YY DD MM YYYY HH Min Sec variables in XP Pro and higher.
#echo off
for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
set "YY=%dt:~2,2%" & 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%"
md "%yyyy%-%mm%-%dd%"
pause
I am trying to set up a 7zip batch file to backup data in an archive with the current date in the file name.
So far I set up
#ECHO OFF
7z a C:\Download\%DATE:~-4%-%DATE:~4,2%-%DATE:~7,2%_Backupfile.7z -mhe -mx0 -r -ssw -w -i#files_included_in_backup.txt -x#files_excluded.txt
pause
The backup itself goes fine, and it should result in a file named JJJ-MM-DD_Backupfile.7z.
Though today on Aug 13 it gives me a file named 2014-8. -01_Backupfile.7z
any idea what´s going wrong?
I am using Windows 8.1 64bit and 7-Zip command line version 9.20.
Give this a shot:
The first four lines of this code will give you reliable YY DD MM YYYY HH Min Sec variables in XP Pro and higher.
#echo off
for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
set "YY=%dt:~2,2%" & 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 "datestamp=%YYYY%-%MM%-%DD%" & set "timestamp=%HH%%Min%%Sec%" & set "fullstamp=%YYYY%-%MM%-%DD%_%HH%-%Min%-%Sec%"
7z a "C:\Download\%datestamp%_Backupfile.7z" -mhe -mx0 -r -ssw -w -i#files_included_in_backup.txt -x#files_excluded.txt
I currently have to windows batch files the first takes all files in a directory ending .bak and adds them to a rar file with todays date in the name
the second one ftp the rar file to another server.
the first ones code is
set path="C:\Program Files\WinRAR\";%path%
set date=%dd-mm-yyyy%
rar a D:\backups\dbs.rar -ri1 -mt2 -ag[dd-mm-yyyy] -m5 D:\backups\*.BAK
del D:\backups\*.BAK
which is called from inside sql server manager when its finished backing up the databases but could easily be run from a scheduled task
the seconds code is
#echo off
echo user Dbusser> ftpuploader.dat
echo ftppassword>> ftpuploader.dat
echo bin>> ftpuploader.dat
echo put %1>> ftpuploader.dat
echo quit>> ftpuploader.dat
ftp -n -s:ftpuploader.dat 127.0.0.1
del ftpuploader.dat
which I manually called from a cmd promt with the name of the rar file as an argument
ftpuploader.bat d:\pathtorar\dbs[21-10-2013].rar
what I want to know is can anyone tell me how to either merge the two files so it automatically uploads the file once its created and finished it or automate the schedule task to that it changes the date bit in the name of the rar file every day
thanks
This requires XP Pro and higher to use Wmic.
It sets the variable with the date, in a reliable manner, and uses that to create the RAR filename and also launch the FTP batch file.
I changed this line if not errorlevel 1 del D:\backups\*.BAK which should protect the *.bak files from being deleted if the RAR archiving fails for any reason.
#echo off
for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
set "YY=%dt:~2,2%" & set "YYYY=%dt:~0,4%" & set "MM=%dt:~4,2%" & set "DD=%dt:~6,2%"
set "datestamp=%DD%-%MM%-%YYYY%"
set path="C:\Program Files\WinRAR\";%path%
rar a D:\backups\dbs[%datestamp%].rar -ri1 -mt2 -m5 D:\backups\*.BAK
if not errorlevel 1 del D:\backups\*.BAK
ftpuploader.bat D:\backups\dbs[%datestamp%].rar
Few things that I don't like in your script: I have no idea what set date=%dd-mm-yyyy% is doing .Not sure when the *bak files are deleted.If you are trying to upload binary files you need to set also the ftp script in binary mode. Here's one possible way to do this without temp files:
!&cls&echo off&setlocal ENABLEDELAYEDEXPANSION
!goto :end_ftp
!rem :: ftp part
open server
Dbusser
ftppassword
prompt
binary
mput *.BAK
bye
:end_ftp
set path="C:\Program Files\WinRAR\";%path%
rem get _date in format DD-MM-YYYY
Set /A "Jan=1,Feb=2,Mar=3,Apr=4,May=5,Jun=6,Jul=7,Aug=8,Sep=9,Oct=10,Nov=11,Dec=12"
Type Nul >"%TEMP%\~.ddf"
Makecab /D RptFileName="%TEMP%\~.rpt" /D InfFileName=Nul /F "%TEMP%\~.ddf" >Nul
Set /P "timestamp=" <"%TEMP%\~.rpt"
For /F "tokens=3-9 delims=: " %%a In ("%timestamp%") Do (
Set /A "year=%%g,month=%%b,day=1%%c-100"
)
Del /Q "%TEMP%\~.*"
Echo year=%year% month=%month% day=%day%
set "_date=%day%-%month%-%year%"
rem date is ready to use
rar a D:\backups\dbs.rar -ri1 -mt2 -ag[%_date%] -m5 D:\backups\%_date%\*.BAK
pushd D:\backups\%_date%\*.BAK
ftp -s:%~dpsnx0
popd
del D:\backups\%_date%\*.BAK /Q /F
RD /S /Q D:\backups\%_date%\
The idea is that you are creating a directory with date name (I suppose your date format is dd-mm-yyyy) , then starts the ftp in this directory and using prompt (to surpass the prompting) and then using mput to upload all files with .bak extension.So no parameters are needed for the ftp script.For here are more explanations for self-contained ftp scripts.