So I'm trying to create a backup script, which creates a backup for the last 10 days. The folder will look like this
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
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"