Disk space and batch

Dikmas Posted messages 393 Status Member -  
dionysoos Posted messages 85 Status Member -
Hello

I created a batch file to back up my MySQL database. The backup works very well, with a backup file created for each day of the week (thanks again to chuka for his strong help).

A problem arises. On some servers where I need to implement the backup strategy, the disk space does not allow the creation of multiple backup files. Therefore, I would like that, if the disk space is insufficient to fully back up the databases, a message is sent (by email or in a log file) informing the administrator that the disk space is low. In other words, I would like to know if there is a way to determine the remaining disk space.

Thanks in advance

Configuration: Windows XP Firefox 3.0.3

10 answers

  1. dionysoos Posted messages 85 Status Member 4
     
    Hello,

    I just modified the script for you to do what you asked. In the loop where we assign a value to NbKoFree with the SET command, don’t forget to add /a to indicate that it is a numeric value.

    @echo off
    rem content of the CHKDSK command put into Temp.txt
    CHKDSK > C:\Temp.txt
    rem retrieval of the line containing the number of free ko on the disk
    FOR /F "delims=" %%a IN ('findstr "Ko" C:\Temp.txt') DO ECHO %%a > C:\Temp1.txt
    rem retrieval of the available allocation number
    FOR /F "tokens=1 delims= " %%i IN (C:\Temp1.txt) DO SET /a NbKoFree=%%i
    Echo you have left: %nbKoFree% ko on the disk
    rem test if the value of the variable is less than the defined value
    IF %NbKoFree% LSS 37000000 ECHO Insufficient disk space >> D:\fichier.txt
    1
  2. Dikmas Posted messages 393 Status Member 63
     
    No one can help me? (It's a bit of a wild upvote, but I really need help :S)
    0
  3. dionysoos Posted messages 85 Status Member 4
     
    Hello there, there isn't a command that does this task automatically, but with some common sense you can manage it with the CHKDSK command. You’ll get a result like this:

    C:>CHKDSK
    The type of file system is NTFS.

    Warning! The parameter F was not specified.
    CHKDSK is running in read-only mode.

    CHKDSK is verifying files (stage 1 of 3)...
    The file verification is complete.
    CHKDSK is verifying indexes (stage 2 of 3)...
    The index verification is complete.
    CHKDSK is recovering lost files.
    CHKDSK is verifying security descriptors (stage 3 of 3)..
    The security descriptor verification is complete.
    CHKDSK has found free space marked as allocated in the
    master file table (MFT) bitmap.
    Correcting errors in the volume map.
    Windows has detected problems with the file system.
    Run CHKDSK with the /F option to fix.

    39013852 KB total disk space.
    25569392 KB in 214858 files.
    60520 KB in 6680 indexes.
    0 KB in bad sectors.
    290016 KB used by the system.
    65536 KB occupied by the page file.
    13093924 KB available on the disk.

    4096 bytes per allocation unit.
    9753463 total allocation units on disk.
    3273481 allocation units available on disk.

    You just need to return the result with echo to a temporary text file, process it to extract only the line we’re interested in
    so this line: "3273481 allocation units available on the disk"
    Then you refine this line to retrieve only 3273481
    to perform these treatments look at the FOR /F command ;)
    And once you have retrieved this value you do a simple calculation
    allocation units available on the disk X bytes per allocation unit
    the result will be the remaining size of your hard drive in bytes.

    There you go, it may sound complicated but I assure you it’s very simple, good luck.
    0
  4. Dikmas Posted messages 393 Status Member 63
     
    Thank you for your response. I’ll see if I can manage to get by.
    0
  5. dionysoos Posted messages 85 Status Member 4
     
    @echo off
    rem contents of the CHKDSK command placed in Temp.txt
    CHKDSK > C:\Temp.txt
    rem retrieve the line containing the number of free kilobytes on the disk
    FOR /F "delims=" %%a in ('findstr "Ko" C:\Temp.txt') DO ECHO %%a > C:\Temp1.txt
    rem retrieve the number of available allocation
    FOR /F "tokens=1 delims= " %%i in (C:\Temp1.txt) DO SET NbKoFree=%%i
    Echo you have left: %nbKoFree% ko on the disk

    Here is something like that, I tested it and it works, but while CHKDSK runs the command for about 5 good minutes you could think the app has crashed but no.

    So it works well but it’s still quite long :(
    0
  6. reno
     
    Do not use CHKDSK at all, it’s dirty. Use the official method.
    0
  7. dionysoos Posted messages 85 Status Member 4
     
    Hello,
    If you could give it to us, I would be delighted; I don’t know it.
    0
  8. Dikmas Posted messages 393 Status Member 63
     
    Hello,

    Thank you Dionysoos. Apart from it taking a bit of time, it works.

    I have another question.

    I’d like that if %nbKoFree% is less than 37,000,000 Ko (for example) it writes "space disque insuffisant" in a txt file.

    You must use the IF statement but the sign "<" does not work. Is there a way to do this?

    IF %nbKoFree% <inférieur à> 37000000 ECHO Espace disque insuffisant >> D:\fichier.txt
    0
  9. Dikmas Posted messages 393 Status Member 63
     
    It works on Windows XP Pro, but not on 2003 Server :/

    It runs the CHKDSK command

    It doesn’t create the Temp1.txt file
    consequently, it doesn’t know where to look for the %NbKoFree% variable

    I did a dumb copy/paste from XP Pro to 2003 Server, the architecture being exactly the same.
    0
  10. dionysoos Posted messages 85 Status Member 4
     
    I don’t know, maybe a question of copyright in writing to check.
    0