rsbackup-lib is a small library of functions common to all rsbackup code. In addition to having common code in one location, allows add on modules to access the same functions by the use statement in perl scripts.
Example:
require 'rsbackup.pm';
functions (sub's) are listed below. This is taken from the internal documentation.
tempFileName
Description
simple wrapper to create a temporary file. DOES NOT REMOVE file
Parameters
None
Returns
- Open File Handle to temp file
- File name with path
sendLogs
Description
Sends a log to the recipient. Log is attached as a MIME encoded message
Parameters
- $logFile -- Full path/filename of log file. DOES NOT COMPRESS
- $mailTo -- single e-mail address of recipient
- $message -- This will be placed in the body of the e-mail
- $TEST_CONDITIONS -- If non-zero, will only print to STDOUT what would happen
- $MAILER_SCRIPT -- Used if $MPACK does not exist.
- $from -- Put into the From: field
- $mailServer -- URL of mail server to use. Defaults to localhost
- $subject -- Placed in the subject line
Returns
- Nothing
compressFile
Description
compresses a file using either gzip or internal library
Parameters
- $filename - name of file to compressed
- $TEST_CONDITIONS - if non-zero, will only send result to STDOUT, will not actually compress file
Returns
- File name created
dateTimeStamp
Description
simple sub that retrieves the date time stamp.
Parameters
- $format Type of data you want to receive, either 'u' for a simple unix number, 't' for yyyymmddhhmmss, and anything else for yyyymmdd
- $theTime -- If passed, this is assumed to be the unix time you want to use. If not passed in, will take current time from computer
Defaults
- $format = 'YYYYMMDD'
- $theTime = system time
Returns
- String containg the date/time
time2HHMMSS
Description
Takes a number of seconds passed in and returns it as HH:MM:SS. used to "pretty print" time
Parameters
- $seconds - An integer number of seconds
Returns
- Above in HH:MM:SS (HH can not exceed 99)
runScript
Description
Runs a script as a forked process, capturing exit status and any output generated on STDOUT (NOT STDERR)
Parameters
- $scriptName - fully qualified path/file of script to run
Returns
- $returnCode - Exit code of script
- $scriptResult - STDOUT capture from script
humanReadable
Description
converts a number to its "Human Readable" form by dividing by 1024 until the "number" is below 1024 the returning that with the appropriate modifier (kMGT). optional second power allows you to use 1000's instead of 1024
Parameters
- $number - the number to be worked on
- $power - the power used to divide by
Defaults
- $power - 1024
Returns
- The result as a 7 digit string containing a 1-3 digit number followed by zero or one of kMGT
rsyncErrorCode
Description
Convert rsync error code into descriptive string
Parameters
- $code - rsync exit status
Returns
- String containing descriptive error message, taken from rsync man page
summarizeRsyncLog
Description
Reads output of rsync -v --stats command and returns a summary.
Parameters
- $fh - open file handle to rsync log
- $rsyncReturn - the status code returned by rsync (defaults to 0)
- $outputFormat - an sprintf format string (see default in second line of code)
Returns
- A multi-line summary of the rsync file, including number of files added/deleted, etc... NOTE: Do not trust this as there have been reports of errors which have not been tracked down.
$outputFormat is simply a sprintf format string for the following parameters, in order
- filesDeleted
- filesAdded
- bytesReceived
- humanReadable bytesReceived
- bytesSent
- humanReadable bytesSent