The FreeBSD Diary

The FreeBSD Diary (TM)

Providing practical examples since 1998

If you buy from Amazon USA, please support us by using this link.
[ HOME | TOPICS | INDEX | WEB RESOURCES | BOOKS | CONTRIBUTE | SEARCH | FEEDBACK | FAQ | FORUMS ]
Scripts / handy tips
 New Topic  |  Go to Top  |  Go to Topic  |  Search  |  Log In   Previous Message  |  Next Message 
 Re: Simple backup script in perl...
Author: Erin 
Date:   17-09-04 21:09

Some updates. I wrote the first version years ago.

#!/usr/bin/perl

#	Part of a group of programs to admin a FreeBSD web/email server.
#	Do what you want with it, just keep the copyright.
#
#	Copyright 2004, Erin Fortenberry
#
#	$Id: backup.pl,v 1.2 2004/08/26 21:01:19 erinf Exp $
#
#	usage: "scriptname -h"
#
#	I use /backup as my backup drive and it is nfs mounted.
#	You can remove the compression on this, but it adds alot
#	to the backup time so I did not make a switch for it.
#
#	The current backup directory it /backup/$hostname/$day.$name.dump.gz
#
#	This script does not check to see if the backup directories exist or
#	if they have enough space for the dump file.
#
#	Requires perl 5.6.1 or newer.
#



use strict;
use warnings;
use Getopt::Std;
use POSIX qw(strftime);
use vars qw($VERSION);

$Getopt::Std::STANDARD_HELP_VERSION = 1;
$VERSION = '1.2';

my @FS = ('/', '/home', '/usr', '/var');
my $day = lc(strftime "%A", localtime);
my $hostname = `/bin/hostname -s`;
my %opt = ('F' => 0, 'd' => 0, 'h' => 0);
my $type;

chomp $hostname;

getopts("Fdh",\%opt);

if ( $opt{h} == 1 ) {

	print STDERR << "EOF";

    usage: $0 [-hqd]

     -h        : this (help) message
     -d        : Dry run, only print what I am going to do
     -F        : Force full backup {type 0}

    example: $0 -h -q -d

EOF
	exit(0)
}

if ( $opt{F} == 1 ) {

	$type = "0"

} else {

	if ($day eq "sunday") {
		$type = "0"
	} else {
		$type = "1"
	}

}

foreach (@FS) {

	my $name = $_;

	if ($name eq '/') {
		$name = '/root';
	};

	$name =~ s/^\///g;

# Unncomment for /backup/$day/$name.dump.gz
#	my $command = '/sbin/dump -' . $type  . ' -auf - ' .  $_ . ' | gzip -q > /backup/' . $day . '/' . $name . '.dump.gz';

# Put a "#" in front of the next line if you uncomment the last line
	my $command = '/sbin/dump -' . $type  . ' -auf - ' .  $_ . ' | gzip -q > /backup/' . $hostname . '/' . $day . '.' . $name . '.dump.gz';

	if ($opt{d}) {
		print($command . "\n");
	} else {
		system($command);
	};
};


exit(0);




 Reply To This Message  |  Forum List  |  Flat View   Newer Topic  |  Older Topic 

 Topics Author  Date
 Simple backup script in perl...   new
Erin 06-08-04 16:28 
 Re: Simple backup script in perl...   new
Jeroen Steggink 17-09-04 12:59 
 Re: Simple backup script in perl...   new
Erin 17-09-04 20:56 
 Re: Simple backup script in perl...   new
Erin 17-09-04 21:09 


 Forum List  |  Need a Login? Register Here 
 User Login
 User Name:
 Password:
 Remember my login:
   
 Forgot Your Password?
Enter your email address or user name below and a new password will be sent to the email address associated with your profile.
How to get the most out of the forum

phorum.org