-4

So I'm trying to create a backup script, which creates a backup for the last 10 days. The folder will look like this

folder

The path to these folders is here: C:\Backups_tester\backups\*

Each folder is around 15GB large, and because of this I want to zip all of them one by one.

It should only zip folders (if there are any), so it will end up looking like this

enter image description here

At the moment my code just creates these folders, and adds a dump from my database into the created folder, if there is more than 10 folders then the oldest (11 folder) will be deleted. So we will always only have 10 folders / now this should be changed to ZIP files.

@echo off
Title Backups
Call :GetFileNameWithDateTime MyCurrentDate
echo %MyCurrentDate%
mkdir C:\Backups_tester\backups\%MyCurrentDate%
set "delMsg="
for /f "skip=10 delims=" %%a in (
  'dir "C:\Backups_tester\backups\*" /t:c /a:d /o:-d /b'
) do (
  if not defined delMsg (
    set delMsg=1
    echo More than 10 found - only the 10 most recent folders will be preserved.
  )
  rd /s /q "C:\Backups_tester\backups\%%a"
)
C:/Backups_tester/bin/mysqldump.exe -u db -p --single-transaction --routines --triggers --host server.db.com --databases database1 > C:/Backups_tester/backups/%MyCurrentDate%/testBackup.sql
pause & exit
::----------------------------------------------------------------------------------
:GetFileNameWithDateTime <FileName>
for /f "skip=1" %%x in ('wmic os get localdatetime') do if not defined MyDate set "MyDate=%%x"
set "%1=%MyDate:~0,4%-%MyDate:~4,2%-%MyDate:~6,2%-%MyDate:~8,2%-%MyDate:~10,2%"
Exit /B
::----------------------------------------------------------------------------------

But how can I do this zipping with 15GB files? Haven't found anything yet which works.

EDIT SOLUTION:

Useing ZIP was better than the suggested question

REM  ---- RAR.exe switches used ----
REM  a            Add files to archive.
REM -ag[format]   Generate archive name using the current date and time.
REM -cfg-         Ignore configuration file and RAR environment variable.
REM -idq          turns on the quiet mode, so only error messages and questions are displayed.
REM -m4           good - use good compression method (more compressive, but slower)
REM -mt1          Set the number of threads.
REM -si           Read data from stdin (standard input), when creating an archive.
REM -y            Assume Yes on all queries.
"C:\...\bin\mysqldump.exe" -u -p --single-transaction --routines --triggers --host database | "C:\Program Files\WinRAR\RAR.exe" a -ag_DDMMYYYY-HHMM -cfg- -idq -m4 -mt1 -sibackup_updater.sql -y "C:\...\...\%MyCurrentDate%\backup__updater.rar"

  • My question is not related to WinRaR since the picture is just to show what I'm trying to do (not with WinRar). The thing I'm trying to get help with is simply just which program / command that can be used for `15GB` folders, since `Expand-Archive` only take 2GB etc, so I just need to be pushed in the right direction. – Mads Sander Høgstrup Nov 01 '21 at 10:44
  • @MadsSanderHøgstrup, I do not care whether or not you have, or are willing to use, WinRAR, or any other utility or scripting mechanism to create your archive files. Your code does not attempt the task, and therefore it is not appropriate for this site. This site is to assist you to fix a single specific and reproducible issue with your submitted code. However, your code isn't exhibiting a reported issue. You should use the search facility to locate and adapt some code, then [edit] your question to include it, or delete your question, and pose it to a site more suited to this type of question. – Compo Nov 01 '21 at 11:21
  • @KJ So you would suggest to avoid zipping the 15GB folders I have? I also thought about that it would take a bit of time to zip the files, and yes recovering the files if something went wrong, would be horrible. – Mads Sander Høgstrup Nov 01 '21 at 11:39

1 Answers1

-1

Windows does not have a zip command line utility before Windows 10. Windows 10 (1903) supposedly has a tar utility with hidden zip support. If you can require WinRar or 7-zip then you can use their tools in your batch file.

If not, you can use WSH to create a empty zip file and then use the shell copy engine to add the files to the archive.

In Windows 8.1 and later you can also use Powershell and the ZipFile .NET class.

Anders
  • 97,548
  • 12
  • 110
  • 164
  • @KJ Good to know but it only exists on Windows 10 and later and the OP did not specify a version. The WSH hack should work back to at least Win2000. – Anders Nov 01 '21 at 11:15
  • @KJ Is there a GB limit for `.tar` files, and are tar the fastest way to zip backups? :) – Mads Sander Høgstrup Nov 01 '21 at 11:15
  • Sorry didn't know windows version was something that would effect this, but I run win10 – Mads Sander Høgstrup Nov 01 '21 at 11:16
  • 1
    I find it rather odd that you post an answer and then close the question as duplicate. That is kind off double standards, is it not? – Gerhard Nov 01 '21 at 12:47
  • @Gerhard I don't see the problem, the other question has more quality answers and should be the canonical. Closing a question you have answered hurts yourself if we are talking about rep (which I don't care about). – Anders Nov 01 '21 at 12:57
  • Yes, that is the point, if the other thread is of better quality, then your answer is not really of use, no? Just an observation. I cannot deem it of use posting my own answer and then closing it to block others from posting possible valuable answers. Maybe it is just me, but it is either of the two, not both. :) Anyway, it is just my opinion, once you've read it, I will delete the comments. – Gerhard Nov 01 '21 at 13:01