Skip to content

How to Calculate the Capacity of Archive Destination in Days

  • by
Do you know the space that the archived destination has in terms of days? Here is a sample shell script code to calculate the maximum days that the archived log files can retain in the destination.
$ vi CalculateArchiveDestCapacity.sh
#!/bin/bash

# Fill DB Basic Information
DBNAME=ORCL
ARCHIVE_DEST=/arch/ORCL # The destination is the location of archived log files.
MOUNT_POINT=arch # The mount point of ARCHIVE_DEST.
RETENTION=7 # How long in days that the archived logs will be retained in the destination according to the backup policy.

# Calculate the total and used space
NUMOFARCH=$(echo "`ls -rtl $ARCHIVE_DEST/* | wc -l`-1" | bc)
TOTALSPACE_KB=`df -k | grep -w $MOUNT_POINT | awk '{print $2}'`
TOTALSPACE_GB=$(echo "scale=2; $TOTALSPACE_KB/1024/1024" | bc)
USEDSPACE_KB=`df -k | grep -w $MOUNT_POINT | awk '{print $3}'`
USEDSPACE_GB=$(echo "scale=2; $USEDSPACE_KB/1024/1024" | bc)

# Calculate the Capacity in days
DAYS=$(echo "scale=2; $TOTALSPACE_KB/$USEDSPACE_KB*$RETENTION" | bc)

# Calculate the Capacity in files
FILES=$(echo "scale=2; $TOTALSPACE_KB/$USEDSPACE_KB*$NUMOFARCH" | bc)

# Output the results
echo "The total space of archive destination $ARCHIVE_DEST is $TOTALSPACE_GB GB."
echo "The current used space of archive destination $ARCHIVE_DEST is $USEDSPACE_GB GB."
echo "The archive destination $ARCHIVE_DEST of $DBNAME can allow archived log files no more than $DAYS days."
echo "The archive destination $ARCHIVE_DEST of $DBNAME can allow archived log files no more than $FILES files."


Let's see the sample result:
$ ./CalculateArchiveDestCapacity.sh
The total space of archive destination /arch/ORCL is 320.00GB.
The current used space of archive destination /arch/ORCL is 160.28 GB.
The archive destination /arch/ORCL of ORCL can allow archived log files no more than 13.64 days.
The archive destination /arch/ORCL of ORCL can allow archived log files no more than 7484.57 files.

Leave a Reply

Your email address will not be published.