Backups?

Joe2003

New Member
Hey

I turned an old pc into a little file server, I appart from the OS partition I have two main backup partitions on two separate disks. I want to mirror the two partitions but I dont really wanna do it with raid, are there any other solutions? I was thinking about building a cron job or something, but what if I only added a single new file?

any help

Cheers
 
You mentioned a cron job, so may I assume you are running a *nix OS?

I do the same type of thing; I have a bash script that:

1) Backs up my /etc /boot /home /usr/local /var/log directories and compresses the backups
2) Mounts whatever partitions I backup to
3) Copies the compressed backups to the mounted partition
4) Runs a bunch of system reports and stores them to the mounted partition so I know the state of the system at the time of the backup
5) Unmounts the backup partitions

I run this every night at midnight under a root cron job. Works beautifully
 
Last edited:
In case you were curious, here's the code:

The actual script starts at the bottom of the code, the rest are the functions that make it work.

Code:
#!/bin/sh

# Filename:	backup.sh
# Description:	Runs an automated backup of system and user files
# Arguments:	None
# Author:	munkyeetr
# Date:		Completed on 05/15/07
#----------------------------------------------------------

## START FUNCTION DECLARATIONS AND DEFINITIONS
#----------------------------------------------------------

# Funct Name:	MountVolume()
# Description:	Passed a path, it will test if the path is mounted
#		and if not, it will attempt to mount the path.
# Arguments:	${vol} - path to mount
# Returns:	n/a
#----------------------------------------------------------
MountVolume() {

	vol=$1

	mount | grep "on ${vol} type" > /dev/null
	if [ $? -eq 0 ]; then
		echo ${vol}" is already mounted"
	else
		sudo mount ${vol}
	fi
}

# Funct Name:	UnmountVolume()
# Description:	Passed a path, it will test if the path is mounted
#		and if it is, it will attempt to unmount the path.
# Arguments:	${vol} - path to unmount
# Returns:	n/a
#----------------------------------------------------------
UnmountVolume() {

	vol=$1

	mount | grep "on ${vol} type" > /dev/null
	if [ $? -eq 0 ]; then
		sudo umount ${vol}
	else
		echo ${vol}" is already unmounted"
	fi	
}

# Funct Name:	CreateBackup()
# Description:	Backs up important system folders and the user's
# 		Home directory to ${dest}
# Arguments:	${dest} - path to backup directory
# Returns:	n/a
#----------------------------------------------------------
CreateBackup() {
	
# set backup destinations; create folder
#----------------------------------------------------------
	dest=${1}"/"`date +%m-%d-%y`
	sudo mkdir ${dest}

# backup select filesystems
#----------------------------------------------------------
	source="/etc"
	sudo tar -zcf ${dest}"/etc".tar ${source}

	source="/boot"
	sudo tar -zcf ${dest}"/boot".tar ${source}

	source="/home"
	sudo tar -zcf ${dest}"/home".tar ${source}

	source="/usr/local"
	sudo tar -zcf ${dest}"/usr-local".tar ${source}

	source="/var/log"
	sudo tar -zcf ${dest}"/var-log".tar ${source}

# generate system reports
#----------------------------------------------------------
	dest=${dest}"/reports"

	sudo mkdir ${dest}

	sudo dpkg --get-selections | grep -v deinstall > installed-packages
	sudo mv installed-packages ${dest}

	sudo uptime > system-uptime
	sudo mv system-uptime ${dest}

	sudo ps aux > system-processes
	sudo mv system-processes ${dest}

	sudo ifconfig > system-ifconfig
	sudo mv system-ifconfig ${dest}

	sudo fdisk -l > system-fdisk
	sudo mv system-fdisk ${dest}

	sudo df -l > system-df
	sudo mv system-df ${dest}
}

#----------------------------------------------------------
## END FUNCTION DECLARATIONS AND DEFINITIONS

## SCRIPT BEGINS HERE
#----------------------------------------------------------

backup_locations=( /media/Backup1	  ## < additional backup locations can be put here >
		   /media/Backup2 )	

# cycle through each backup location and perform the backup
for location in ${backup_locations[@]}
do
	MountVolume ${location}
	CreateBackup ${location}
	UnmountVolume ${location}	
done

#----------------------------------------------------------
## SCRIPT ENDS HERE

exit
 
Back
Top