KB Logo

TOLIS Group Knowledge Base

Browse KB by category:
Go to KB #:
Glossary
Email   Bookmark



Clean your hard drive and regain your disk space.

Views: 13025
Votes: 1
Posted: 02 Oct, 2007

Clean Old User Files and Gain Space

There are three different time specifications to every file on a Unix system. While many backup utilities will maintain the current change time (ctime ), and some even track the file's modification time (mtime ), BRU also keeps track of the file's access time (atime ).

The importance in keeping track of a file's atime is when it comes time to clean up old and unused files. On an average system, 40% to 60% of all user files haven't been touched by the user that created them in more than 120 days. These files clutter up your system, wasting disk space and inodes needlessly.

But, if your backup utility doesn't reset the atime of the files as it backs them up, the atime gets updated by the system to the time that the backup utility touches the file for read (a type of access). This means that files will have an atime that is as current as your last backup.

BRU, on the other hand, checks each file's atime before it backs it up and resets it after it is backed up. Also, in the event of a restore, BRU will reset the restored file's atime to what it was when BRU backed it up.

This script allows you to see the three different time stamps for a given file.

#!/bin/sh
#
# showtime Show the times of a file
#
F=$1
if [ $# -gt 2 ]
   then
     echo "ERROR: more than one file specified"
exit 1

fi
if [ "$F" = "" ]
then
echo "ERROR: No file specified"
exit 1
fi
MTIME=`ls -l $F` # modification time
CTIME=`ls -lc $F` # inode change time
ATIME=`ls -lu $F` # access time

echo "$MTIME (MTIME)\n$CTIME (CTIME)\n$ATIME (ATIME)"
With this is mind, we must ask why some companies require you to spend large sums of cash to purchase a disk grooming and migration tool. Here's a standard shell script that will check for files that haven't been accessed in a given period, write them to two (or more) tapes and then erase them from your system.
#!/bin/sh

#######################################
#
# Shell script to perform file migration based on access time
#
# Copyright (c) 1995,2001 The TOLIS Group, Inc.
#
# Permission is granted to use or modify
#
# TOLIS Group Makes no warranties as to the suitability of this software.
#
# It is the responsibility of the user to determine the usefulness of
# this information.
#
# TOLIS Group is not responsible for any damages that occur
# because of the use or misuse of this script
#
#######################################

# Variables used below

AGE=120
# How STALE should a file be (in days)

DEVICE=/dev/rmt99 # edit for your device!
DATE=`date +%m-%d-%y %H:%M`
LABEL="Migration Backup $ - DO NOT OVERWRITE!"

#
# Build a list of file that haven't been touched in AGE days
#
Build_List() {

echo "Building list of files for migration...be patient"
find /home -atime +$ -print >> /tmp/migrate_list

echo "File list complete. Stored as /tmp/migrate_list."
}

#
# Backup the files and run a bit comparison verification
#
Backup_Files () {
echo "Backing up files to tape ..."
bru -cvvL $ -a -G -f$ - </tmp/migrate_list bru -dddvv -f $
result=$?
if [ $result -ne 0 ]
then
echo "Some files have changed since the backup occured."
echo "This invalidates the list of files being processed for migration."
echo
echo "Aborting migration operation."
exit 1
fi
}

#
# Ask the operator for permission to delete the files and remove them
# if permitted.
#
Remove_Files () {
echo "You are about to delete the files that were previously backed up
echo -n "permanently! Are you sure you wish to continue (y/N)? "
read continue
case $ in
n|N)
echo "Aborting the file deletion!"
exit 1

;;
y|Y)
echo "Deleting files ..."
cat /tmp/migrate_list | rm -rf
echo "Deletion Complete!"
exit 0

;;

*)
echo "Aborting the file deletion!"
exit 1
;;

esac
}
######################################
#
# Main Operation Begins here!
#
# You may add additional Backup_Files calls below if you wish to create
# more than two copies of the files.
#
######################################
Build_List
Backup_Files
echo -n "The first tape copy is complete. Insert tape 2 and press ENTER"
read answer
Backup_Files
echo -n "The second tape copy is complete. Be sure to lock these tapes away!"
Remove_Files

Keep in mind that this script is designed as an EXAMPLE. It may not be directly functional on your system. Also, it depends on the validity of the atime information of your files. If you aren't using BRU's -a option in your backups, your files will only be as stale as your last backup!

Others in this Category
document Important LTO-4 SAS and SAS HBA Information
document Understanding Unix/Linux Timestamp's
document I want to use/create barcodes for my tapes, what type of barcode do I use?
document Linear Tape File System (LTFS) Caveats
document Setting Up Global Exclusions With The BRUXPAT File
» More Articles



RSS
Powered by KnowledgebasePublisher
Page Load Time: 0.031933 seconds / 31.933 milliseconds.
Page File Size: 26139 bytes.