You are not logged in.
Pages: 1
Well, I made a simple backup/restore script in Bash, it is capable of backing up files/directories to two different locations, in 3 ways,
1. locally (to another harddrive)
2. Server (to a server)
3. To both the server and to your local harddrive
It is also capable of restoring the backed up files
it is quite ugly at the moment though, and probably unsafe to use...but it seems to work...don't forget to edit the relative paths (there are 4 variables that can be changed, and then there are the files you wish to backup)
i will to this more gracefully in a few days
UPDATE: Updated the script to a little more flexible...still a lot of work to do, but hey...give me time
if anyone wants it and might enjoy it, here it is:
#!/bin/sh
#################################################
# #
# CyberTron Backup-Script #
# This script is made up by functions #
# and is capable of both backing up #
# and restore data #
# licensed under GPL #
# #
#################################################
set_variables()
{
user=cybertron
home=/home/$user
backup_server=/mnt/backup/Micke/backup/backup-$(date +%d%m%y)
backup_server_date=/mnt/backup/Micke/backup/backup-
backup_server_etc=/mnt/backup/Micke/backup/backup-$(date +%d%m%y)/etc
backup_server_home=/mnt/backup/Micke/backup/backup-$(date +%d%m%y)/$user
ls_server=/mnt/backup
backup_local_date=/blandad/backup/backup-
backup_local=/blandad/backup/backup-$(date +%d%m%y)
backup_local_etc=/blandad/backup/backup-$(date +%d%m%y)/etc
backup_local_home=/blandad/backup/backup-$(date +%d%m%y)/$user
ls_local=/blandad/backup
}
create_dirs_local()
{
echo "Creating necessary directories in: $backup_local"
mkdir -p $backup_local || { echo 'Failed to create dir'; rm -r $backup_local; exit 1; }
mkdir -p $backup_local_etc || { echo 'Failed to create dir'; rm -r $backup_local; exit 1; }
mkdir -p $backup_local_home || { echo 'Failed to create dir'; rm -r $backup_local; exit 1; }
}
create_dirs_server()
{
echo "Creating necessary directories in: $backup_server"
mkdir -p $backup_server || { echo 'Failed to create dir'; rm -r $backup_server; exit 1; }
mkdir -p $backup_server_etc || { echo 'Failed to create dir'; rm -r $backup_server; exit 1; }
mkdir -p $backup_server_home || { echo 'Failed to create dir'; rm -r $backup_server; exit 1; }
}
check_local()
{
# Check for previous backup today
if [ -e $backup_local ]; then
echo "Removing directories from $backup_local"
rm -R $backup_local || { echo 'Failure removing directories'; exit 1; }
create_dirs_local
local_backup
else
create_dirs_local
local_backup
fi
}
check_server()
{
# Check for previous backup today
if [ -e $backup_server ]; then
echo "Removing directories from $backup_server"
rm -R $backup_server || { echo 'Failure removing directories'; exit 1; }
create_dirs_server
server_backup
else
create_dirs_server
server_backup
fi
}
##### Local Backup ######
local_backup()
{
echo "Backing up locally"
####### Copying files from /etc ######
echo "Copying files from /etc"
etc_files="rc.conf hosts fstab profile ld.so.conf /etc/conf.d/dhcpcd /etc/X11/xorg.conf /etc/conf.d/wireless"
for app in $etc_files ; do
cd /etc
echo "Copying $app"
cp $app $backup_local_etc || { echo 'Failed to copy file'; rm -r $backup_local; exit 1; }
done
###### Copying files from /home/cybertron #######
home_files=".xinitrc .conkyrc .cvspass .imwheelrc backup.sh e17build_new.sh .e .e16 .mozilla .thunderbird .gaim pkgbuilds skola"
echo "Beginning copying files from $home"
for app in $home_files ; do
cd $home
echo "Copying $app"
cp -r $app $backup_local_home || { echo 'Failed to copy file'; rm -r $backup_local; exit 1; }
done
chown -R cybertron:users $backup_local
echo "Everything was successfully transfered to $backup_local"
echo "Press any key to continue"
read $wait
clear
}
##### Server Backup ######
server_backup()
{
echo "Backing up to the Server"
####### Copying files from /etc ######
echo "Copying files from /etc"
etc_files="rc.conf hosts fstab profile ld.so.conf /etc/conf.d/dhcpcd /etc/X11/xorg.conf /etc/conf.d/wireless"
for app in $etc_files ; do
cd /etc
echo "Copying $app"
cp $app $backup_server_etc || { echo 'Failed to copy file'; rm -r $backup_server; exit 1; }
done
###### Copying files from /home/cybertron #######
home_files=".xinitrc .conkyrc .cvspass .imwheelrc backup.sh e17build_new.sh .e .e16 .mozilla .thunderbird .gaim pkgbuilds skola"
echo "Beginning copying files from $home"
for app in $home_files ; do
cd $home
echo "Copying $app"
cp $app $backup_server_home || { echo 'Failed to copy file'; rm -r $backup_server; exit 1; }
done
chown -R cybertron:users $backup_server
echo "Everything was successfull transfered to $backup_server"
echo "Press any key to continue"
read $wait
clear
}
##### Restore Local ######
restore_local()
{
# Show which backups exists
clear
echo "MUST BE ROOT"
ls $ls_local
echo "Which date do you want to restore to (day/month/year): "
read b_date
#####Copying files to /etc #######
echo "Copying files to /etc"
etc_files="rc.conf hosts fstab profile ld.so.conf"
for app in $etc_files ; do
cd $backup_local_date$b_date_date$b_date/etc
echo "Copying $app"
cp $app /etc || { echo 'Failed to copy file'; exit 1; }
done
echo "Copying xorg.conf"
cp $backup_local_date$b_date/etc/xorg.conf /etc/X11 || { echo 'Failed to copy file'; exit 1; }
echo "Copying dhcpcd"
cp $backup_local_date$b_date/etc/dhcpcd /etc/conf.d || { echo 'Failed to copy file'; exit 1; }
echo "Copying wireless"
cp $backup_local_date$b_date/etc/wireless /etc/conf.d || { echo 'Failed to copy file'; exit 1; }
###### Copying files to /home/cybertron #######
home_files=".xinitrc .conkyrc .cvspass .imwheelrc backup.sh e17build_new.sh .e .e16 .mozilla .thunderbird .gaim pkgbuilds skola"
echo "Beginning copying files from $home"
for app in $home_files ; do
cd $backup_local_date$b_date/$user
echo "Copying $app"
cp -r $app $home || { echo 'Failed to copy file'; exit 1; }
done
chown -R cybertron:users $home
echo "Everything was successfully restored"
echo "Press any key to continue"
read $wait
clear
}
##### Restore Server ######
restore_server()
{
# Show which backups exists
clear
echo "MUST BE ROOT"
ls $ls_server
echo "Which date will you restore to: (day/month/year) "
read b_date2
echo "MUST BE ROOT"
#####Copy files to /etc ######
echo "Copying files to /etc"
etc_files="rc.conf hosts fstab profile ld.so.conf"
for app in $etc_files ; do
cd $backup_server_date$b_date2/etc
echo "Copying $app"
cp -r $app /etc || { echo 'Failed to copy file'; exit 1; }
done
echo "Copying xorg.conf"
cp $backup_server_date$b_date2/etc/xorg.conf /etc/X11 || { echo 'Failed to copy file'; exit 1; }
echo "Copying dhcpcd"
cp $backup_server_date$b_date2/etc/dhcpcd /etc/conf.d || { echo 'Failed to copy file'; exit 1; }
echo "Copying wireless"
cp $backup_server_date$b_date2/etc/wireless /etc/conf.d || { echo 'Failed to copy file'; exit 1; }
###### Copying files to /home/cybertron #######
home_files=".xinitrc .conkyrc .cvspass .imwheelrc backup.sh e17build_new.sh .e .e16 .mozilla .thunderbird .gaim pkgbuilds skola"
echo "Beginning copying files from $home"
for app in $home_files ; do
cd $backup_server_date$b_date2/$user
echo "Copying $app"
cp -r $app $home || { echo 'Failed to copy file'; exit 1; }
done
chown -R cybertron:users $home
echo "Everything was successfully restored"
echo "Press any key to continue"
read $wait
clear
}
clear
while [ 1 = 1 ]
do
echo "####################################################"
echo "# Welcome to backup-script v.0.01 #"
echo "# Please make a selection below #"
echo "# 1. Backup to /blandad #"
echo "# 2. Backup to /mnt/backup #"
echo "# 3. Backup to both #"
echo "# 4. Restore from /blandad #"
echo "# 5. Restore from /mnt/backup #"
echo "# q. Quit #"
echo "####################################################"
read val
# Variables that are used in this script
set_variables
case $val in
[1]*)
check_local
clear
;;
[2]*)
check_server
clear
;;
[3]*)
check_local
check_server
clear
;;
[4]*)
restore_local
clear
;;
[5]*)
restore_server
clear
;;
[qQ]*)
exit 1;
;;
*)
clear
echo "Choose 1-5 or q(uit)"
;;
esac
done
http://www.linuxportalen.com -> Linux Help portal for Linux and ArchLinux (in swedish)
Dell Inspiron 8500
Kernel 2.6.14-archck1 (selfcompiled)
Enlightenment 17
Offline
Pages: 1