-1

After Googling and "researching" for over 3 hours to no avail, i have turned here to possibly get some help to my issue. Either if its possible or not to some extent.

This is a bit messy i know, but i'm fairly new to this.

What im trying to do.

  1. I want to Backup a File which adds it to a archive folder With a Timestamp to it. YYYY-MM-DD Which then contains the File

    • 2021-03-09.rar
      • File01.db
  2. Then it takes the created file and adds it to a Backup.rar

    • Backup.rar
      • 2021-03-09.rar
        • File01.db

Now i got this to work, My only problem here is that it instead overwrites the current existing File "2021-03-09.rar" in the Archive "Backup.rar" with the new one, instead of adding a number to the new backup that i added.

This is how i want/it should do;

Backup01: 2021-03-09.rar
Backup02: 2021-03-09-01.rar
Backup03: 2021-03-09-02.rar
Backup04: 2021-03-09-03.rar > and so on.

Code/what i have tried

I have tried using the commands "M" and "U" but same result, i tried using -or as well, which should rename files automatically if a file with the same name exists, but it doesnt work and the file(2021-03-09.rar) in my archive(Backup.rar) gets overwritten instead with the new backup(2021-03-09.rar).

Code:

"%ProgramFiles%\WinRAR\rar.exe" a -agYYYY-MM-DD -cfg -ep1 -m5 -r -y "C:\Users\%UserProfile%\Documents\0-Background\BAT FILES\Database Backups\Backups\.rar" "C:\Users\%UserProfile%\Documents\0-Background\BAT FILES\Database Backups\File01db"
"%ProgramFiles%\WinRAR\rar.exe" a -or -ep "C:\Users\%UserProfile%\Documents\0-Background\BAT FILES\Database Backups\Backups.rar" "C:\Users\%UserProfile%\Documents\0-Background\BAT FILES\Database Backups\Backups\*"

While i know its not the smartest way to add a rar file to another rar file, its what i decided to do, it might be smarter to just have the bat file create a folder that it then adds to the archive or if it creates a folder in winrar and then adds the file to the folder in the archie, but it seemed to advanced.

Syphex
  • 11
  • 1

1 Answers1

0

Use YYYYMMDD and add an archive number, where the archive number is a numeric value starting from 1. That will generate unique names even when the YYYY-MM-DD-NN format mask is used more than once in the same day.

WinRAR a -agYYYY-MM-DD-NN backup

WinRAR searches for already existing archives with that generated name and if found, increments the archive number to generate an unused name.

Refer to WinRAR, Help. Help topics and search for '-ag'

Selwyn
  • 1
  • 1
  • I tried this, but it won't create the backup with the NN parameter it just ignores it completely. – Syphex Mar 30 '21 at 05:18