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.
functions (sub's) are listed below. This is taken from the internal documentation.
simple wrapper to create a temporary file. DOES NOT REMOVE file
- Open File Handle to temp file
- File name with path
Sends a log to the recipient. Log is attached as a MIME encoded message
- $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
compresses a file using either gzip or internal library
- $filename - name of file to compressed
- $TEST_CONDITIONS - if non-zero, will only send result to STDOUT, will not actually compress file
- File name created
simple sub that retrieves the date time stamp.
- $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
- $format = 'YYYYMMDD'
- $theTime = system time
- String containg the date/time
Takes a number of seconds passed in and returns it as HH:MM:SS. used to "pretty print" time
- $seconds - An integer number of seconds
- Above in HH:MM:SS (HH can not exceed 99)
Runs a script as a forked process, capturing exit status and any output generated on STDOUT (NOT STDERR)
- $scriptName - fully qualified path/file of script to run
- $returnCode - Exit code of script
- $scriptResult - STDOUT capture from script
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
- $number - the number to be worked on
- $power - the power used to divide by
- $power - 1024
- The result as a 7 digit string containing a 1-3 digit number followed by zero or one of kMGT
Convert rsync error code into descriptive string
- $code - rsync exit status
- String containing descriptive error message, taken from rsync man page
Reads output of rsync -v --stats command and returns a summary.
- $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)
- 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
- humanReadable bytesReceived
- humanReadable bytesSent