-
-
Save Waxolunist/1885529 to your computer and use it in GitHub Desktop.
| :: **************************************************************************** | |
| :: Delete all files except the n newest | |
| :: **************************************************************************** | |
| :: ---------------------------------------------------------------------------- | |
| :: Usage: delete_except_newest.bat DIR N FILTER | |
| :: Example: delete_except_newest.bat C:\tmp 10 *.txt | |
| :: ---------------------------------------------------------------------------- | |
| :: **************************************************************************** | |
| :: **************************************************************************** | |
| :: Init | |
| REM CLS | |
| @ECHO off | |
| SetLocal EnableDelayedExpansion | |
| :: **************************************************************************** | |
| @ECHO. | |
| :: **************************************************************************** | |
| :: Variables | |
| :: **************************************************************************** | |
| SET DIR=%1% | |
| SET /a N=%2% | |
| SET FILTER=%3% | |
| :: **************************************************************************** | |
| REM list all filenames, except directories, sorted by date of creation, newest first | |
| for /F "skip=%N% tokens=*" %%G in ('dir /T:C /O:-D /B /A:-D "%DIR%\%FILTER%"') DO DEL "%DIR%\%%G | |
| @ECHO Program exited successfully. | |
| :: **************************************************************************** |
Wie könnte man delete_except_newest . 7 *.gz als Aufgabe in der Aufgabenplanung 1 Mal im Monat (vorerst, dann 1 Mal täglich, damit es immer 7 tar.gz-Archive bleiben) ausführen?
Da kenne ich mich mit Windows zu wenig aus. Aber hier sind ein paar gute Antworten https://stackoverflow.com/questions/7195503/setting-up-a-cron-job-in-windows
damit klappt es
mklink /D "A:\charly-export-database-tar-gz-mo-mi" "A:\FULLBACKUP-MO&MI-CAUTION-DO-NOT-CHANGE\Solutio\DatabaseBackup\postgres"
in der Aufgabenplanung steht:
Programm/Skript: A:\charly-export-database-tar-gz-mo-mi\delete_except_newest.bat
Argumente hinzufügen (optional): A:\charly-export-database-tar-gz-mo-mi\ 7 *.gz
es geht hauptsächlich darum, den unmöglichen Pfad mit dem &-Zeichen über mklink zu umgehen.
man achte auf die Syntax von mklink https://superuser.com/a/597552
solutio hat sein charly-internes Backup-Skript (zumindest wenn ich es manuell modifiziere und selbst Aufgaben mit selbstgeschrieben Befehlen in der Aufgabenplanung speichere) gebacken bekommen. Es sind nie mehr als 8 tar.gz Archive.
Es war mir eine Ehre 🦸♂️
Schön wenn man helfen kann. 😊