Backup script
I created a backup script for my data & system and i'd like to share it.
I have a 320GB hdd (1) as my main hard drive, and a 160GB hdd (2) as a backup drive (i keep this one in a drawer nearby, disconnected from the computer).
What i wanted was to create a partial copy of 1 on 2, such that 2 would contain the entire system (bootable) + a part of my data.
1. You need to have the same filesystem on both (i have ext4). Maybe it works with a mix of ext3 and 4, but it's better to have just one. The partitioning scheme on hdd 1 doesn't matter, but for hdd 2 you need a single partition to which you backup.
2. The scripts:
backup
#!/bin/sh
# rsync backup script
sudo rsync -av --delete-excluded --exclude-from="excl" / "$1"
sudo touch "$1"/BACKUP
This one is very simple. You rsync in archive mode (which ensures that symbolic links, devices, attributes, permissions, ownerships, etc. are preserved) and exclude the files that match the patterns from excl.
The / is the source from where you backup (in our case the whole root) and "$1" is the destination to where you backup (this is passed as an argument to the script).
excl
# Include
+ /dev/console
+ /dev/initctl
+ /dev/null
+ /dev/zero
+ /media/win
+ /var/run/mpd
+ /home/wooptoo/music/Amestecate
+ /home/wooptoo/music/script
+ /home/wooptoo/music/list.txt
+ /home/wooptoo/music/.hg*
# Exclude
- /home/wooptoo/dl/*
- /home/wooptoo/games/kits/*
- /home/wooptoo/mov/*
- /home/wooptoo/music/*
- /dev/*
- /media/*
- /media/win/*
- /mnt/*
- /proc/*
- /sys/*
- /tmp/*
- /var/run/*
- /var/run/mpd/*
This is a bit more tricky. It's an exclude (and include) file in rsync format.
Exclude: I excluded my games, movies and music from the backup, and also the system directories /dev, /media, /mnt, /proc, /sys, /tmp, /var/run. These are excluded because their content is created at runtime by the system. Note that the direcotries themselves are preserved (you need them!) but they are empty.
Include: even though i excluded /dev, i need to include 4 file from it (which are not dinamically created by udev), these are console, initctl, null, zero.
I also included the directories /media/win and /var/run/mpd. But these are empty, because their content was excluded (in the exclude section).
3. So we got these two files: backup and excl.
Mount the backup hdd, let's say at /media/backup/ and run the script:
./backup /media/backup/
rsync will backup the whole root to that destination. I excluded game kits, music and movies from my backup because they are just too large to fit on hdd 2, and it would also take a lot of time to backup and keep in sync afterwards.
4. After the sync is finished you need to install a boot loader on hdd2, so you can have a working copy of your system.
Open the grub console and type in:
root (hd1,0)
setup (hd1)
The root command tells grub where your system is installed (in this case hdd 2, first partition).
Setup tells grub where to install the boot loader. In my example it is installed in the MBR of hdd 2.
The problem here is that the boot loader installs correctly, but its menu entries are for the partitions of the main system, not the backup system. So if you'll try to boot the backup system, it won't work.
You can fix this by creating a custom menu.lst for the backup hdd. But i prefer not to do this, in order to have an accurate copy of my data. I just prefer to edit the entries from the boot menu on the fly if i need to boot the backup directly. But you can automatically add a custom menu.lst to the backup hdd from the backup script:
#!/bin/sh
# rsync backup script
sudo rsync -av --delete-excluded --exclude-from="excl" / "$1"
sudo cp ~/custom.menu.lst "$1"/boot/grub/menu.lst
sudo touch "$1"/BACKUP
5. Reboot and try out your new system.
I think this approach (system + data backup) is better than just data backup because if something goes wrong with the main hdd, you can always swap in the backup one and continue working. Besides this, you now have another working system, from which you can recover the main one without the need of live CDs.
In my setup both hdds are SATA with AHCI, so they are hot-pluggable. You can plugin the backup drive, run the backup script, and disconnect it. This is very advantageous because you don't have to reboot.
But you can use an USB stick/hdd as backup drive if you only have IDE.
I would like to know what do you think of my backup strategy. Is it good or am i doing it wrong? Are there better methods? What backup strategy do you use? etc.
Last edited by wooptoo (2009-10-24 01:40:46)
I use the following to rotate four backups and backup my root and home separately and hard-link common files between all the backups. I run this weekly to have backups of the last four weeks while using barely more space then one full backup would. It is not super customisable as it is my personal script and I've been wanting to add in a check to see whether the backup location is actually mounted, but I've not gotten to it just yet
#!/bin/bash
# Script to rotate three backups of / and /home and make a new incremental
# backup. No arguments required. Make sure the correct disk is mounted at
# $PAR, though!
# Original command ran to create the first backup of /home :
# /usr/bin/sudo /usr/bin/rsync --progress --stats -avz \
# --exclude-from=/home/ramses/home_backup_excludes --delete-exludes \
# /home/ /media/seadisc/home_backup.0
# Variables and paths
PAR="/media/seadisc/backup"
HOME_EXCLUDES="/usr/local/bin/backup_config/home_backup_excludes"
ROOT_EXCLUDES="/usr/local/bin/backup_config/root_backup_excludes"
SUDO="/usr/bin/sudo"
MV="/bin/mv"
RM="/bin/rm"
RSYNC="/usr/bin/rsync"
DATE="/bin/date"
TEE="/usr/bin/tee"
# Home backups
echo "Moving previous /home backups ..."
$SUDO $RM -rf $PAR/home_backup.3
$SUDO $MV $PAR/home_backup.2 $PAR/home_backup.3
$SUDO $MV $PAR/home_backup2_date $PAR/home_backup3_date
$SUDO $MV $PAR/home_backup.1 $PAR/home_backup.2
$SUDO $MV $PAR/home_backup1_date $PAR/home_backup2_date
$SUDO $MV $PAR/home_backup.0 $PAR/home_backup.1
$SUDO $MV $PAR/home_backup0_date $PAR/home_backup1_date
echo "Doing incremental backup of /home ..."
$SUDO $RSYNC --progress --stats -av \
--exclude-from=${HOME_EXCLUDES} \
--delete --delete-excluded \
--link-dest=$PAR/home_backup.1 \
/home/ $PAR/home_backup.0
$SUDO $DATE | $TEE $PAR/home_backup0_date > /dev/null
# Root backups
echo "Moving previous / backups ..."
$SUDO $RM -rf $PAR/root_backup.3
$SUDO $MV $PAR/root_backup.2 $PAR/root_backup.3
$SUDO $MV $PAR/root_backup2_date $PAR/root_backup3_date
$SUDO $MV $PAR/root_backup.1 $PAR/root_backup.2
$SUDO $MV $PAR/root_backup1_date $PAR/root_backup2_date
$SUDO $MV $PAR/root_backup.0 $PAR/root_backup.1
$SUDO $MV $PAR/root_backup0_date $PAR/root_backup1_date
echo "Doing incremental backup of / ..."
$SUDO $RSYNC --progress --stats -av \
--exclude-from=${ROOT_EXCLUDES} \
--delete --delete-excluded \
--link-dest=$PAR/root_backup.1 \
/ $PAR/root_backup.0
$SUDO $DATE | $TEE $PAR/root_backup0_date > /dev/null
Similar Messages
-
How do I create a automated file backup script?
I need a backup script to move files from the MAC to Google Drive everyday at a certain time. I tried using automator to create a calendar flow but it does not run when I set it up in calendar. Can someone provide me a simple script template with Apple script or tell me how to do this?
How are you backing up? The Automator Calendar alarm should work. Test with Automator first by creating a Workflow, then see if it works within Automator when you click "Run"
-
Parallel Backup script written in python
I'm writing a backup script in python, based on one I wrote in BASH earlier on. Both of these leverage rsync, but I decided to move to a python implementation because python is much more flexible than BASH. My goals with the new implementation are to back up the system, home folder, and my documents folder to a set of multiple primary, secondary, and tertiary disks, respectively. The method is as follows:
1. check for the existence of disks and create folders which will contain mountpoints for each category of disk.
2. decrypt and mount disks found under subfolders within those category folders, creating the mountpoints if they don't exist.
3. syncronize the aforementioned data to the mounted disks using rsync, doing all three classes of disk in parallel.
4. unmount and close disks
This is really my first serious python program, and I realize that it's a bit complicated. My code is rather sloppy, as well, perhaps understandably so given my novice status. My only other programming experience is with BASH scripts, but I digress.
Here is the code for the script (about 250 lines). It is written as a series of functions, and I'm uncertain as to whether functions or objects would work better. Additionally, I'm sure there's a python function provided by the os module analogous to the sync system call, but I've yet to find it in my python desk reference. The backup functions need work, and I'm still trying to figure out how to get them to loop through the mounted disks in each folder and copy to them. I require assistance in determining how to write the backup functions to do as outlined above, and how to run them in parallel. This is still a work in progress, mind.
#!/usr/bin/python
# Backup Script
#### preferences ####
# set your primary/secondary backup disks, encryption, and keyfile (if applicable) here.
# backup disks
# primary and secondary backups. As used here,
# primary backups refer to backups of the entire system made to an external drive
# secondary backups refer to backups made of individual folders, such as documents
# primary backup disks by UUID:
global PDISKS
PDISKS = ("/dev/disk/by-uuid/16d64026-28bd-4e1f-a452-74e76bb4d47b","")
# secondary backups by UUID.
global SDISKS
SDISKS = ()
# tertiary disks by UUID:
global TDISKS
TDISKS = ("/dev/disk/by-uuid/39543e6e-cf50-4416-9669-e97a6abd2a37","")
# backup paths
# these are the paths of the folders you wish to back up to secondary
# and tertiary disks, respectively. Primary disks are set to back up the
# contents of the root filesystem (/*). NO TRAILING SLASHES.
global SBACKUP
SBACKUP = "/home/bryant"
global TBACKUP
TBACKUP = "/home/bryant/docs"
# use encryption:
use_encryption = True
# keyfile
# set the full path to your keyfile here
# this assumes a single keyfile for all backup disks
# set this to None if you don't have a single keyfile for all of your backups
keyfile = "/usr/local/bin/backup.keyfile"
# import modules
import os, subprocess, sys
### preliminary functions ###
# these do the setup and post-copy work
def check_dirs():
"""checks that the folders which contain the mountpoints exist, creates them if they don't"""
print("checking for mountpoints...")
p = os.path.isdir("/mnt/pbackup")
if p == True:
print("primary mountpoint exists.")
elif p == False:
print("mountpoint /mnt/pbackup does not exist.\n\tcreating...")
os.mkdir("/mnt/pbackup")
s = os.path.isdir("/mnt/sbackup")
if s == True:
print("secondary mountpoint exists.")
elif s == False:
print("mountpoint /mnt/pbackup does not exist.\n\tcreating...")
os.mkdir("/mnt/sbackup")
t = os.path.isdir("/mnt/tbackup")
if t == True:
print("tertiary mountpoint exists.")
elif t == False:
print("mountpoint /mnt/tbackup does not exist.\n\tcreating...")
os.mkdir("/mnt/tbackup")
def mount_disks():
"""mounts available backup disks in their respective subdirectories"""
pfolder = 1
sfolder = 1
tfolder = 1
pmapper = "pbackup" + str(pfolder)
smapper = "sbackup" + str(sfolder)
tmapper = "tbackup" + str(tfolder)
for pdisk in PDISKS:
e = os.path.islink(pdisk)
if e == True:
subprocess.call("sync",shell=True)
kf=os.path.isfile(keyfile)
if kf == True:
print("keyfile found. Using keyfile to decrypt...")
subprocess.call("sudo cryptsetup luksOpen " + pdisk + " " + pmapper + " --key-file " + keyfile,shell=True)
if kf == False:
print("keyfile not found or keyfile not set. \t\nAsking for passphrase...")
subprocess.call("sudo cryptsetup luksOpen " + pdisk + " " + pmapper,shell=True)
f = os.path.isdir("/mnt/pbackup/pbak" + str(pfolder))
if f == True:
subprocess.call("mount " + "/dev/mapper/" + pmapper + " /mnt/pbak" + str(pfolder),shell=True)
pfolder += 1
elif f == False:
os.mkdir("/mnt/pbackup/pbak" + str(pfolder))
subprocess.call("mount " + "/dev/mapper/" + pmapper + " /mnt/pbak" + str(pfolder),shell=True)
pfolder += 1
for sdisk in SDISKS:
e = os.path.islink(sdisk)
if e == True:
subprocess.call("sync",shell=True)
kf=os.path.isfile(keyfile)
if kf == True:
print("keyfile found. Using keyfile to decrypt...")
subprocess.call("sudo cryptsetup luksOpen " + sdisk + " " + smapper + " --key-file " + keyfile,shell=True)
if kf == False:
print("keyfile not found or keyfile not set. \t\nAsking for passphrase...")
subprocess.call("sudo cryptsetup luksOpen " + sdisk + " " + smapper,shell=True)
f = os.path.isdir("/mnt/sbackup/sbak" + str(sfolder))
if f == True:
subprocess.call("mount " + "/dev/mapper/" + smapper + " /mnt/sbackup/sbak" + str(sfolder),shell=True)
sfolder += 1
elif f == False:
os.mkdir("/mnt/sbackup/sbak" + str(folder))
subprocess.call("mount " + "/dev/mapper/" + smapper + " /mnt/sbackup/sbak" + str(sfolder),shell=True)
sfolder += 1
for tdisk in TDISKS:
e = os.path.islink(tdisk)
if e == True:
subprocess.call("sync",shell=True)
kf=os.path.isfile(keyfile)
if kf == True:
print("keyfile found. Using keyfile to decrypt...")
subprocess.call("sudo cryptsetup luksOpen " + tdisk + " " + tmapper + " --key-file " + keyfile,shell=True)
if kf == False:
print("keyfile not found or keyfile not set. \t\nAsking for passphrase...")
subprocess.call("sudo cryptsetup luksOpen " + tdisk + " " + tmapper,shell=True)
f = os.path.isdir("/mnt/tbackup/tbak" + str(tfolder))
if f == True:
subprocess.call("mount " + "/dev/mapper/" + tmapper + " /mnt/pbak" + str(tfolder),shell=True)
tfolder += 1
elif f == False:
os.mkdir("/mnt/tbackup/tbak" + str(tfolder))
subprocess.call("mount " + "/dev/mapper/" + tmapper + " /mnt/tbak" + str(tfolder),shell=True)
tfolder += 1
def umount_disks():
"""unmounts and relocks disks"""
subprocess.call("umount /mnt/pbackup*",shell=True)
subprocess.call("umount /mnt/sbackup*",shell=True)
subprocess.call("umount /mnt/tbackup*",shell=True)
subprocess.call("cryptsetup luksClose /dev/mapper/pbackup*",shell=True)
subprocess.call("cryptsetup luksClose /dev/mapper/sbackup*",shell=True)
subprocess.call("cryptsetup luksClose /dev/mapper/tbackup*",shell=True)
def check_disks():
"""checks to see how many disks exist, exits program if none are attached"""
pdisknum = 0
sdisknum = 0
tdisknum = 0
for pdisk in PDISKS:
p = os.path.islink(pdisk)
if p == True:
pdisknum += 1
elif p == False:
print("disk " + pdisk + " not detected.")
for sdisk in SDISKS:
s = os.path.islink(sdisk)
if s == True:
sdisknum += 1
elif s == False:
print("disk " + sdisk + " not detected.")
for tdisk in TDISKS:
t = os.path.islink(tdisk)
if t == True:
tdisknum += 1
elif t == False:
print("disk " + tdisk + " not detected.")
total = pdisknum + sdisknum + tdisknum
if total == 0:
print("ERROR: no disks detected.")
sys.exit()
elif total > 0:
print("found " + str(total) + " attached backup disks")
print(str(pdisknum) + " Primary")
print(str(sdisknum) + " secondary")
print(str(tdisknum) + " tertiary")
return total, pdisknum, sdisknum, tdisknum
### backup functions ###
# these need serious work. Need to get them to loop through available mounted
# disks in their categories and then execute rsync
def pbackup():
"""calls rsync to backup the entire system to all pdisks"""
dirs = os.listdir("/mnt/pbackup")
for dir in dirs:
m = os.path.ismount(dir)
if m == True:
subprocess.call("sync",shell=True)
print("syncing disks with rsync...")
# subprocess.call("rsync --progress --human-readable --numeric-ids --inplace --verbose --archive --delete-after --hard-links --xattrs --delete --compress --skip-compress={*.jpg,*.bz2,*.gz,*.tar,*.tar.gz,*.ogg,*.mp3,*.tar.xz,*.avi} /* /mnt/pbackup/" + dir + "/ --exclude={/sys/*,/mnt/*,/proc/*,/dev/*,/lost+found,/media/*,/tmp/*,/home/*/.gvfs/*,/home/*/downloads/*,/opt/*,/run/*",shell=True)
print("test1")
subprocess.call("sync",shell=True)
print("disk synced with disk " + pdisk + ".")
print("sync with disk " + pdisk + " complete.")
elif m == False:
continue
def sbackup():
"""calls rsync to backup everything under SBACKUP folder to all sdisks"""
dirs = os.listdir("/mnt/sbackup")
for dir in dirs:
m = os.path.ismount(dir)
if m == True:
subprocess.call("sync",shell=True)
# subprocess.call("rsync --progress --human-readable --numeric-ids --inplace --verbose --archive --delete-after --hard-links --xattrs --delete --compress --skip-compress={*.jpg,*.bz2,*.gz,*.tar,*.tar.gz,*.ogg,*.mp3,*.tar.xz,*.avi} SBACKUP/* /mnt/sbackup/" + dir + "/",shell=True)
print("test2")
subprocess.call("sync",shell=True)
print("disk synced with disk " + pdisk + ".")
print("sync with disk " + sdisk + " complete.")
elif m == False:
continue
def tbackup():
"""calls rsync to backup everything under TBACKUP folder to all tdisks"""
dirs = os.listdir("/mnt/tbackup")
for dir in dirs:
m = os.path.ismount(dir)
if m == True:
subprocess.call("sync",shell=True)
# subprocess.call("rsync --progress --human-readable --numeric-ids --inplace --verbose --archive --delete-after --hard-links --xattrs --delete --compress --skip-compress={*.jpg,*.bz2,*.gz,*.tar,*.tar.gz,*.ogg,*.mp3,*.tar.xz,*.avi} TBACKUP/* /mnt/sbackup/" + dir + "/",shell=True)
print("test3")
subprocess.call("sync",shell=True)
print("disk synced with disk " + pdisk + ".")
print("sync with disk " + sdisk + " complete.")
elif m == False:
continue
#### main ####
# check for root access:
r=os.getuid()
if r != 0:
print("ERROR: script not run as root.\n\tThis script MUST be run as root user.")
sys.exit()
elif r == 0:
# program body
check_dirs()
check_disks()
mount_disks()
# pbackup()
# sbackup()
tbackup()
umount_disks()
print("backup process complete.")
Last edited by ParanoidAndroid (2013-08-07 20:01:07)I've run into a problem on line 149. I'm asking the program to list the directories under the top-level backup directories under /mnt, check to see if each one is a mountpoint, and if it is unmount it. It does this, but it appears to recurse into the directories under the directories I'm asking it to check. The output is:
checking for mountpoints...
primary mountpoint exists.
secondary mountpoint exists.
tertiary mountpoint exists.
disk /dev/disk/by-uuid/16d64026-28bd-4e1f-a452-74e76bb4d47b not detected.
found 1 attached backup disks
0 Primary
0 secondary
1 tertiary
keyfile found. Using keyfile to decrypt...
mounting tbackup1 at /mnt/tbak1
test3
not a mountpoint
not a mountpoint
not a mountpoint
not a mountpoint
not a mountpoint
not a mountpoint
not a mountpoint
not a mountpoint
not a mountpoint
not a mountpoint
not a mountpoint
not a mountpoint
not a mountpoint
not a mountpoint
Device /dev/mapper/pbackup* is not active.
Device /dev/mapper/sbackup* is not active.
backup process complete.
here is the code for the entire script. It's been much modified from the previously posted version, so I included all of the code versus the section in question for reference. As I said, the section that seems to be causing the issue is on line 149.
#!/usr/bin/python
# Backup Script
#### preferences ####
# set your primary/secondary backup disks, encryption, and keyfile (if applicable) here.
# backup disks
# primary and secondary backups. As used here,
# primary backups refer to backups of the entire system made to an external drive
# secondary backups refer to backups made of individual folders, such as documents
# primary backup disks by UUID:
global PDISKS
PDISKS = ["/dev/disk/by-uuid/16d64026-28bd-4e1f-a452-74e76bb4d47b"]
# secondary backups by UUID.
global SDISKS
SDISKS = []
# tertiary disks by UUID:
global TDISKS
TDISKS = ["/dev/disk/by-uuid/39543e6e-cf50-4416-9669-e97a6abd2a37"]
# backup paths
# these are the paths of the folders you wish to back up to secondary
# and tertiary disks, respectively. Primary disks are set to back up the
# contents of the root filesystem (/*). NO TRAILING SLASHES.
global SBACKUP
SBACKUP = "/home/bryant"
global TBACKUP
TBACKUP = "/home/bryant/docs"
# use encryption:
use_encryption = True
# keyfile
# set the full path to your keyfile here
# this assumes a single keyfile for all backup disks
# set this to None if you don't have a single keyfile for all of your backups
keyfile = "/usr/local/bin/backup.keyfile"
# import modules
import os, subprocess, sys
### preliminary functions ###
# these do the setup and post-copy work
def check_dirs():
"""checks that the folders which contain the mountpoints exist, creates them if they don't"""
print("checking for mountpoints...")
if os.path.isdir("/mnt/pbackup"):
print("primary mountpoint exists.")
else:
print("mountpoint /mnt/pbackup does not exist.\n\tcreating...")
os.mkdir("/mnt/pbackup")
if os.path.isdir("/mnt/sbackup"):
print("secondary mountpoint exists.")
else:
print("mountpoint /mnt/pbackup does not exist.\n\tcreating...")
os.mkdir("/mnt/sbackup")
if os.path.isdir("/mnt/tbackup"):
print("tertiary mountpoint exists.")
else:
print("mountpoint /mnt/tbackup does not exist.\n\tcreating...")
os.mkdir("/mnt/tbackup")
def mount_disks(wdisk):
"""mounts available backup disks in their respective subdirectories"""
pfolder = 1
sfolder = 1
tfolder = 1
pmapper = "pbackup"
smapper = "sbackup"
tmapper = "tbackup"
if wdisk == "p":
for pdisk in PDISKS:
if os.path.islink(pdisk):
subprocess.call("sync",shell=True)
if os.path.isfile(keyfile):
print("keyfile found. Using keyfile to decrypt...")
subprocess.call("sudo cryptsetup luksOpen " + pdisk + " " + pmapper + str(pfolder) + " --key-file " + keyfile,shell=True)
else:
print("keyfile not found or keyfile not set. \t\nAsking for passphrase...")
subprocess.call("sudo cryptsetup luksOpen " + pdisk + " " + pmapper + str(pfolder),shell=True)
if os.path.isdir("/mnt/pbackup/pbak" + str(pfolder)):
print("mounting " + pmapper + str(pfolder) + " at /mnt/pbak" + str(pfolder))
subprocess.call("mount " + "/dev/mapper/" + pmapper + str(pfolder) + " /mnt/pbackup/pbak" + str(pfolder),shell=True)
pfolder += 1
else:
os.mkdir("/mnt/pbackup/pbak" + str(pfolder))
subprocess.call("mount " + "/dev/mapper/" + pmapper + str(pfolder) + " /mnt/pbackup/pbak" + str(pfolder),shell=True)
pfolder += 1
elif wdisk == "s":
for sdisk in SDISKS:
if os.path.islink(sdisk):
subprocess.call("sync",shell=True)
if os.path.isfile(keyfile):
print("keyfile found. Using keyfile to decrypt...")
subprocess.call("sudo cryptsetup luksOpen " + sdisk + " " + smapper + str(sfolder) + " --key-file " + keyfile,shell=True)
else:
print("keyfile not found or keyfile not set. \t\nAsking for passphrase...")
subprocess.call("sudo cryptsetup luksOpen " + sdisk + " " + smapper + str(sfolder),shell=True)
if os.path.isdir("/mnt/sbackup/sbak" + str(sfolder)):
print("mounting " + smapper + str(sfolder) + " at /mnt/sbak" + str(sfolder))
subprocess.call("mount " + "/dev/mapper/" + smapper + str(sfolder) + " /mnt/sbackup/sbak" + str(sfolder),shell=True)
sfolder += 1
else:
os.mkdir("/mnt/sbackup/sbak" + str(folder))
subprocess.call("mount " + "/dev/mapper/" + smapper + str(sfolder) + " /mnt/sbackup/sbak" + str(sfolder),shell=True)
sfolder += 1
elif wdisk == "t":
for tdisk in TDISKS:
if os.path.islink(tdisk):
subprocess.call("sync",shell=True)
if os.path.isfile(keyfile):
print("keyfile found. Using keyfile to decrypt...")
subprocess.call("sudo cryptsetup luksOpen " + tdisk + " " + tmapper + str(tfolder) + " --key-file " + keyfile,shell=True)
else:
print("keyfile not found or keyfile not set. \t\nAsking for passphrase...")
subprocess.call("sudo cryptsetup luksOpen " + tdisk + " " + tmapper + str(tfolder),shell=True)
if os.path.isdir("/mnt/tbackup/tbak" + str(tfolder)):
print("mounting " + tmapper + str(tfolder) + " at /mnt/tbak" + str(tfolder))
subprocess.call("mount " + "/dev/mapper/" + tmapper + str(tfolder) + " /mnt/tbackup/tbak" + str(tfolder),shell=True)
if os.path.islink(tdisk):
tfolder += 1
else:
os.mkdir("/mnt/tbackup/tbak" + str(tfolder))
subprocess.call("mount " + "/dev/mapper/" + tmapper + " /mnt/tbackup/tbak" + str(tfolder),shell=True)
tfolder += 1
def umount_disks():
"""unmounts and relocks disks"""
pdirs = os.listdir("/mnt/pbackup")
sdirs = os.listdir("/mnt/sbackup")
tdirs = os.listdir("/mnt/tbackup")
for pdir in pdirs:
if os.path.ismount("/mnt/pbackup/" + pdir):
subprocess.call("umount /mnt/pbackup/" + pdir,shell=True)
else:
print("not a mountpoint")
for sdir in sdirs:
if os.path.ismount("/mnt/sbackup/" + sdir):
subprocess.call("umount /mnt/sbackup/" + sdir,shell=True)
else:
print("not a mountpoint")
for tdir in tdirs:
if os.path.ismount("/mnt/tbackup/" + tdir):
subprocess.call("umount /mnt/tbackup/" + tdir,shell=True)
else:
print("not a mountpoint")
subprocess.call("cryptsetup luksClose /dev/mapper/pbackup*",shell=True)
subprocess.call("cryptsetup luksClose /dev/mapper/sbackup*",shell=True)
subprocess.call("cryptsetup luksClose /dev/mapper/tbackup*",shell=True)
def check_disks():
"""checks to see how many disks exist, exits program if none are attached"""
pdisknum = 0
sdisknum = 0
tdisknum = 0
for pdisk in PDISKS:
if os.path.islink(pdisk):
pdisknum += 1
else:
print("\ndisk " + pdisk + " not detected.")
for sdisk in SDISKS:
if os.path.islink(sdisk):
sdisknum += 1
else:
print("\ndisk " + sdisk + " not detected.")
for tdisk in TDISKS:
if os.path.islink(tdisk):
tdisknum += 1
else:
print("\ndisk " + tdisk + " not detected.")
total = pdisknum + sdisknum + tdisknum
if total == 0:
print("\nERROR: no disks detected.")
sys.exit()
elif total > 0:
print("found " + str(total) + " attached backup disks")
print(str(pdisknum) + " Primary")
print(str(sdisknum) + " secondary")
print(str(tdisknum) + " tertiary")
return total, pdisknum, sdisknum, tdisknum
### backup functions ###
# these need serious work. Need to get them to loop through available mounted
# disks in their categories and then execute rsync
def pbackup():
"""calls rsync to backup the entire system to all pdisks"""
dirs = os.listdir("/mnt/pbackup")
for dir in dirs:
if os.path.ismount("/mnt/pbackup/" + dir) == True:
subprocess.call("sync",shell=True)
print("syncing disks with rsync...")
subprocess.call("rsync --progress --human-readable --numeric-ids --inplace --verbose --archive --delete-after --hard-links --xattrs --delete --compress --skip-compress={*.jpg,*.bz2,*.gz,*.tar,*.tar.gz,*.ogg,*.mp3,*.tar.xz,*.avi} /* /mnt/pbackup/" + dir + "/ --exclude={/sys/*,/mnt/*,/proc/*,/dev/*,/lost+found,/media/*,/tmp/*,/home/*/.gvfs/*,/home/*/downloads/*,/opt/*,/run/*",shell=True)
subprocess.call("sync",shell=True)
else:
continue
def sbackup():
"""calls rsync to backup everything under SBACKUP folder to all sdisks"""
dirs = os.listdir("/mnt/sbackup")
for dir in dirs:
if os.path.ismount("/mnt/sbackup/" + dir):
subprocess.call("sync",shell=True)
subprocess.call("rsync --progress --human-readable --numeric-ids --inplace --verbose --archive --delete-after --hard-links --xattrs --delete --compress --skip-compress={*.jpg,*.bz2,*.gz,*.tar,*.tar.gz,*.ogg,*.mp3,*.tar.xz,*.avi} " + SBACKUP + "/* /mnt/sbackup/" + dir + "/",shell=True)
subprocess.call("sync",shell=True)
else:
continue
def tbackup():
"""calls rsync to backup everything under TBACKUP folder to all tdisks"""
dirs = os.listdir("/mnt/tbackup")
for dir in dirs:
if os.path.ismount("/mnt/tbackup/" + dir):
subprocess.call("sync",shell=True)
subprocess.call("rsync --progress --human-readable --numeric-ids --inplace --verbose --archive --delete-after --hard-links --xattrs --delete --compress --skip-compress={*.jpg,*.bz2,*.gz,*.tar,*.tar.gz,*.ogg,*.mp3,*.tar.xz,*.avi} " + TBACKUP + "/* /mnt/sbackup/" + dir + "/",shell=True)
subprocess.call("sync",shell=True)
else:
continue
#### main ####
# check for root access:
r=os.getuid()
if r != 0:
print("ERROR: script not run as root.\n\tThis script MUST be run as root user.")
sys.exit()
elif r == 0:
# program body
check_dirs()
d=check_disks()
if d[1] > 0:
mount_disks("p")
pbackup()
elif d[2] > 0:
mount_disks("s")
sbackup()
elif d[3] > 0:
mount_disks("t")
tbackup()
umount_disks()
print("backup process complete.")
Last edited by ParanoidAndroid (2013-08-11 00:32:02) -
Hello -
I want to compare file system dates (on AIX) for a backup script. For example, after the backup completes, I want to compare the timestamps on each backed up file with the the time the backup started. I should not see any timestamps prior to the start time of the backup.
Does anyone know how to do this in Unix?
Any help is greatly appreciated!
Thanks,
MikeAt the beginning of your backup use the touch command on a flag file of some kind. This will set the modified date to the current system time.
At the end of your backup compare the modified time of the flag file to the other files. Something like:
touch flag.file
< do your backup >
filelist=`ls filespec for files of interest`
for f in $filelist
do
if [ $f -nt flag.test ]; then
report it
fi
done[pre]
HTH
John -
Hello,
I'm trying to backup script (*.ICMS) with schedule task, do you now if it's possible?
I find the manual export in script editor but do it one by one ...
I need your help
Thanks a lotYou cannot "back up" an individual .icms file.
If you back up the logger (xxxx_sideA) database, that will include all the Scripts (along with all your other configuration).
iow - the Scripts are part of the ICM database, not a separate entity. -
Oracle version : 11G release 2
Platform : AIX
After going through various OTN posts, i wrote the below Cold backup script (Untested). If there are any unnecessary stuff or enhancements required, please let me know
$ rman target /
RMAN>
run
allocate channel c1 type disk format '/u05/rmanbkp/%d_COLD_DB_%u';
sql 'alter system archive log current';
shutdown immediate;
startup mount;
backup database including current controlfile tag='mydbname_full_bkp';
backup spfile tag = 'mydbname_SPFILE';
release channel c1;
}Hi T.Boyd
What do you guys think of the backup script? Any room for improvement? I found in a small percentage of the shutdown immediate commands issued, the instance hangs (specially when the machine is very busy).
I have modified my rman coldbackup the procedure to:
shutdown abort;
host 'sleep 3';
startup restrict;
shutdown immediate;
startup mount;Maybe you can add more channels to improve performance. You can use more resources as there are no users on the database anyway....
Regards,
Tycho -
I need help making a backup script
I'm trying to create this full system backup script that I plan to run manually. I have some commands to compress and extract my root directory and everything in it, but they're not complete because there are a few other features I would like to have. The problem is that I have no idea how to implement these specific features, and my googling of bash scripting documentation only left me confused and at square 1. This is what I have so far (just commands I can run in the terminal):
To compress:
sudo tar -cpf ~/archive.tar.gz / --exclude=/proc
To extract & restore:
sudo tar -xpf /home/agi/archive.tar.gz -C /
I want this script to:
1. allows me to run as
sh ~/.bin/backup.sh [directory to back up]
What I mean is there should be some sort of parameter in the script so that when I run it, I can choose whatever directory I want to compress rather than just be limited to just /.
2. puts finished .tar.gz in my home directory (I plan to transfer the archive to external media or online later; this gives me the freedom to not need to have a specific drive connected to run the script). I already have this in the commands, but I just wanted to point out that this is important.
3. names finished .tar.gz DD-MM-YY-backup.tar.gz where DD is day, MM is month, YY is year.
4. the "sudo" part works correctly. That is, the script, when run, asks for a password and can be granted root permissions (or is granted root permissions in some other way) so that I can back up all parts of my system without these sorts of errors.
5. shows some sort of progress indicator. Either a progress bar, shows the tar program output, or something that gives me an indication that the script is working and perhaps how long it will take. This one is really optional, for as long as the process is working properly then I'm ok. But if it is possible and not ridiculously complicated or difficult, it would be very nice.What I mean is there should be some sort of parameter in the script so that when I run it, I can choose whatever directory I want to compress rather than just be limited to just /.
On my backup script, I specify $* which should accept any arguments passed to the script.. ex: $ ./backup.sh /source/folder /source/folder2.
in the script:
#!/bin/sh
tar -cpf $HOME/$(date +%d%m%Y)-backup.tar.gz $* --exclude=/proc
2. puts finished .tar.gz in my home directory (I plan to transfer the archive to external media or online later; this gives me the freedom to not need to have a specific drive connected to run the script). I already have this in the commands, but I just wanted to point out that this is important.
In the above script, that is what the ~ or $HOME should do..
3. names finished .tar.gz DD-MM-YY-backup.tar.gz where DD is day, MM is month, YY is year.
Same thing, the above script should do the trick, you might want to modify the date parameters (check the date manual)
4. the "sudo" part works correctly. That is, the script, when run, asks for a password and can be granted root permissions (or is granted root permissions in some other way) so that I can back up all parts of my system without these sorts of errors.
You could put something to prevent the script from running unless you are root, or you could have it prompt for a password and use sudo within the script. I would recommend the first. Here is a code snippet:
#Check for root
if [ $(whoami) != "root" ]; then
echo "Error: You cannot perform this operation unless you are root"
exit 1
fi
5. shows some sort of progress indicator. Either a progress bar, shows the tar program output, or something that gives me an indication that the script is working and perhaps how long it will take. This one is really optional, for as long as the process is working properly then I'm ok. But if it is possible and not ridiculously complicated or difficult, it would be very nice.
You might be able to use a similar program to tar, but with progress. Maybe someone else could shed some light here..
Hope this helps... -
Rman hot backup script gives error in R12.
hi experts
i m facing following prob when run the backup script. 1 day before the same script runs correctily but now it gives me error at the allocatioion of channel rest of command run correctly.
[root@testerp rman_log]# cat UAT_daily_rman_hot_bkp_01-11-14_140301.log
-bash: /root/.bash_profile: Permission denied
Recovery Manager: Release 11.1.0.7.0 - Production on Sat Jan 11 14:03:01 2014
Copyright (c) 1982, 2007, Oracle. All rights reserved.
connected to target database: UAT (DBID=2855851979)
connected to recovery catalog database
RMAN> 2> 3> 4> 5> 6> 7> 8> 9> 10> 11> 12>
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-00558: error encountered while parsing input commands
RMAN-01009: syntax error: found "end-of-file": expecting one of: "allocate, alter, advise, backup, beginline, blockrecover, catalog, change, copy, convert, crosscheck, configure, duplicate, debug, delete, execute, endinline, flashback, host, mount, open, plsql, recover, release, replicate, report, restore, resync, repair, }, set, setlimit, sql, switch, startup, shutdown, send, show, transport, validate"
RMAN-01007: at line 12 column 1 file: standard input
RMAN>
RMAN>
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-00558: error encountered while parsing input commands
RMAN-01009: syntax error: found "identifier": expecting one of: "for"
RMAN-01008: the bad identifier was: c2
RMAN-01007: at line 1 column 18 file: standard input
RMAN>
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-00558: error encountered while parsing input commands
RMAN-01009: syntax error: found "identifier": expecting one of: "for"
RMAN-01008: the bad identifier was: c3
RMAN-01007: at line 1 column 18 file: standard input
RMAN>
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-00558: error encountered while parsing input commands
RMAN-01009: syntax error: found "identifier": expecting one of: "for"
RMAN-01008: the bad identifier was: c4
RMAN-01007: at line 1 column 18 file: standard input
RMAN>
Starting backup at 11-JAN-14
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=362 device type=DISK
channel ORA_DISK_1: starting incremental level 1 datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00021 name=/d06/UAT/proddata/a_txn_data06.dbf
input datafile file number=00392 name=/d06/UAT/db/apps_st/data/a_txn_data01.dbf
input datafile file number=00401 name=/d06/UAT/db/apps_st/data/a_txn_data02.dbf
input datafile file number=00402 name=/d06/UAT/db/apps_st/data/a_txn_data03.dbf
input datafile file number=00022 name=/d06/UAT/proddata/a_txn_data07.dbf
input datafile file number=00014 name=/d06/UAT/db/apps_st/data/a_txn_data04.dbf
input datafile file number=00020 name=/d06/UAT/proddata/a_txn_data05.dbf
input datafile file number=00011 name=/d06/UAT/db/apps_st/data/sysaux01.dbf
input datafile file number=00018 name=/d06/UAT/db/apps_st/data/sysaux02.dbf
input datafile file number=00023 name=/d06/UAT/proddata/a_txn_data08.dbf
input datafile file number=00379 name=/d06/UAT/db/apps_st/data/undo01.dbf
input datafile file number=00024 name=/d06/UAT/proddata/sysaux03.dbf
input datafile file number=00025 name=/d06/UAT/proddata/sysaux04.dbf
input datafile file number=00033 name=/d06/UAT/proddata/a_txn_ind11.dbf
input datafile file number=00029 name=/d06/UAT/proddata/a_txn_ind09.dbf
input datafile file number=00030 name=/d06/UAT/proddata/a_txn_ind10.dbf
input datafile file number=00015 name=/d06/UAT/db/apps_st/data/a_txn_ind06.dbf
input datafile file number=00026 name=/d06/UAT/db/apps_st/data/a_txn_ind07.dbf
input datafile file number=00028 name=/d06/UAT/db/apps_st/data/a_txn_ind08.dbf
input datafile file number=00393 name=/d06/UAT/db/apps_st/data/a_txn_ind01.dbf
input datafile file number=00403 name=/d06/UAT/db/apps_st/data/a_txn_ind02.dbf
input datafile file number=00404 name=/d06/UAT/db/apps_st/data/a_txn_ind03.dbf
input datafile file number=00405 name=/d06/UAT/db/apps_st/data/a_txn_ind04.dbf
input datafile file number=00406 name=/d06/UAT/db/apps_st/data/a_txn_ind05.dbf
input datafile file number=00400 name=/d06/UAT/db/apps_st/data/a_media01.dbf
input datafile file number=00353 name=/d06/UAT/db/apps_st/data/system08.dbf
input datafile file number=00013 name=/d06/UAT/db/apps_st/data/system12.dbf
input datafile file number=00352 name=/d06/UAT/db/apps_st/data/system09.dbf
input datafile file number=00394 name=/d06/UAT/db/apps_st/data/a_ref01.dbf
input datafile file number=00407 name=/d06/UAT/db/apps_st/data/a_ref02.dbf
input datafile file number=00396 name=/d06/UAT/db/apps_st/data/a_summ01.dbf
input datafile file number=00395 name=/d06/UAT/db/apps_st/data/a_int01.dbf
input datafile file number=00008 name=/d06/UAT/db/apps_st/data/a_queue02.dbf
input datafile file number=00027 name=/d06/UAT/db/apps_st/data/a_queue03.dbf
input datafile file number=00031 name=/d06/UAT/db/apps_st/data/a_queue04.dbf
input datafile file number=00399 name=/d06/UAT/db/apps_st/data/a_queue01.dbf
input datafile file number=00001 name=/d06/UAT/db/apps_st/data/system01.dbf
input datafile file number=00002 name=/d06/UAT/db/apps_st/data/system02.dbf
input datafile file number=00003 name=/d06/UAT/db/apps_st/data/system03.dbf
input datafile file number=00004 name=/d06/UAT/db/apps_st/data/system04.dbf
input datafile file number=00005 name=/d06/UAT/db/apps_st/data/system05.dbf
input datafile file number=00398 name=/d06/UAT/db/apps_st/data/a_archive01.dbf
input datafile file number=00295 name=/d06/UAT/db/apps_st/data/system06.dbf
input datafile file number=00351 name=/d06/UAT/db/apps_st/data/system07.dbf
input datafile file number=00354 name=/d06/UAT/db/apps_st/data/system11.dbf
input datafile file number=00288 name=/d06/UAT/db/apps_st/data/system10.dbf
input datafile file number=00012 name=/d06/UAT/db/apps_st/data/apps_ts_tools01.dbf
input datafile file number=00016 name=/d06/UAT/db/apps_st/data/a_ref03.dbf
input datafile file number=00019 name=/d06/UAT/db/apps_st/data/MLSEIGL01.dbf
input datafile file number=00032 name=/d06/UAT/db/apps_st/data/RMAN01.dbf
input datafile file number=00397 name=/d06/UAT/db/apps_st/data/a_nolog01.dbf
input datafile file number=00314 name=/d06/UAT/db/apps_st/data/portal01.dbf
input datafile file number=00017 name=/d06/UAT/db/apps_st/data/a_int02.dbf
input datafile file number=00006 name=/d06/UAT/db/apps_st/data/ctxd01.dbf
input datafile file number=00010 name=/d06/UAT/db/apps_st/data/olap.dbf
input datafile file number=00009 name=/d06/UAT/db/apps_st/data/odm.dbf
input datafile file number=00007 name=/d06/UAT/db/apps_st/data/owad01.dbf
channel ORA_DISK_1: starting piece 1 at 11-JAN-14
[root@testerp rman_log]#
backup script is below:
in this script it returns error only at the channel allocaition rest of all backup command i run manually or with scirpt it runs correctly.4
i m not able to know why it returns error only at challnel allocation 1 day before it runs correctly.
[orauat@testerp rman_script]$ cat rman_backup.sh
#!/bin/sh
#ORACLE_SID=UAT
#BACKUP_START_TIME='date +"%y""%m""%d"_"%H""%M""%S"'
#ORACLE_HOME=/d06/UAT/db/tech_st/11.1.0
#PATH=$PATH:${ORACLE_HOME}:${ORACLE_HOME}/bin
#export ORACLE_SID
#export ORACLE_HOME
#export PATH
/d06/UAT/db/tech_st/11.1.0/bin/rman catalog rman/rman007 target sys/sysuat <<EOF
run
allocate channel c1 device type disk format '/d06/UAT/rman_hot_backup/Daily_backup%d_Arch_%c_%U';
sql 'alter system switch logfile';
sql 'alter system switch logfile';
sql 'alter system archive log current';
delete expired archivelog all;
crosscheck archivelog all;
backup archivelog all;
delete noprompt archivelog all completed before 'sysdate-4' backed up 1 times to disk;
allocate channel c2 device type disk format '/d06/UAT/rman_hot_backup/Daily_backup%d_DB_%c_%U';
allocate channel c3 device type disk format '/d06/UAT/rman_hot_backup/Daily_backup%d_DB_%c_%U';
allocate channel c4 device type disk format '/d06/UAT/rman_hot_backup/Daily_backup%d_DB_%c_%U';
backup incremental level 1 database;
delete expired backup device type disk;
delete obsolete device type disk;
release channel c1;
release channel c2;
release channel c3;
release channel c4;
exit
EOF
regards
pritesh ranjanyes the script is edited
i have add some command line and edit it for take the full backup level=0 on the same directory with different formant name but location is same.
can i take full backup level 0 and incremental backup level 1 in the same directory with the different format name.
for exp:
allocate channel c2 device type disk format '/d06/UAT/rman_hot_backup/Daily_backup%d_DB_%c_%U';
allocate channel c3 device type disk format '/d06/UAT/rman_hot_backup/Daily_backup%d_DB_%c_%U';
allocate channel c4 device type disk format '/d06/UAT/rman_hot_backup/Daily_backup%d_DB_%c_%U';
i allocate these three channel for incremental level 1 backup;
the backup is done successfully without any error.
after that i have change
allocate channel c2 device type disk format '/d06/UAT/rman_hot_backup/Weekly_backup%d_DB_%c_%U';
allocate channel c3 device type disk format '/d06/UAT/rman_hot_backup/Weekly_backup%d_DB_%c_%U';
allocate channel c4 device type disk format '/d06/UAT/rman_hot_backup/Weekly_backup%d_DB_%c_%U';
backup database incremental level 0
after doing the above changes it get the error. with the channel location.
i have to schedule daily incremental backup level 1 and weekly full backup level 0.
plz suggest me i have to take incremental 1 and full incremental level 0 backup on seperate directory for different format name.
regards
pritesh ranjan -
Install & Backup Scripts - 1st try at scripting
Here is my first real attempt at bash scripting. The first is a simple script to back up some of my files and configs everytime my comp is shutdown:
#!/bin/bash
#Archive and compress files
tar -czf /home/casey/ArchBoxBak.tar.gz /home/casey/.bashrc /home/casey/.conkyrc /home/casey/.xinitrc /home/casey/scripts /home/casey/.keytouch2 /home/casey/.config
#Copy to Server
scp /home/casey/ArchBoxBak.tar.gz [email protected]:/home/casey
#Clean up
rm /home/casey/ArchBoxBak.tar.gz
The second is a semi-automated install script to be run after a fresh install from a cd:
#!/bin/bash
#Script to install programs and set themes
#Must be run as root
echo ; clear
#Check that the user updated the kernel and restarted before proceeding
echo -n "Have you already updated the kernel and restarted? (Y/n) "
read Keypress1
case "$Keypress1" in
[Nn])
pacman -S kernel26
echo
echo "Now please reboot and re-run this script. Exiting... "
exit
break
esac
#Install yaourt
echo
echo -n "Install Yaourt? (REQUIRED to continue) (Y/n) "
read Keypress2
case "$Keypress2" in
[Nn])
echo
echo "This script cannot continue without Yaourt. Exiting... "
exit
echo
echo >> /etc/pacman.conf
echo "[archlinuxfr]" >> /etc/pacman.conf
echo "#yaourt repo" >> /etc/pacman.conf
echo "Server = http://repo.archlinux.fr/i686" >> /etc/pacman.conf
esac
echo
echo -n "Verify the right archlinux.fr repo was added? (Y/n) "
read Keypress3
case "$Keypress3" in
[Nn])
break
nano /etc/pacman.conf
echo ; clear
esac
echo
echo "Continuing to install Yaourt... "
echo
pacman -Sy
pacman -S yaourt
#Install powerpill
echo "Powerpill is a wrapper for Pacman that increases the speed "
echo "of package downloads by using aria2c as a download accelerator "
echo "and is REQUIRED for this script to continue. "
echo
echo -n "Install Powerpill? (Y/n) "
read Keypress4
case "$Keypress4" in
[Nn])
echo
echo "This script cannot continue without Powerpill. Exiting... "
exit
yaourt -S powerpill
esac
#Update packages installed from cd
echo
echo -n "Update ALL installed packages? (Y/n) "
read Keypress4a
case "$Keypress4a" in
[Nn])
break
powerpill -Syu
esac
#Install user defined programs
echo
echo -n "Install extra programs? (Y/n) "
read Keypress5
case "$Keypress5" in
[Nn])
break
pacman -S xorg
powerpill -S openbox obconf obmenu firefox gstreamer0.10-ffmpeg 0.10.4-1 flashplugin gstreamer0.10-ffmpeg gstreamer0.10-ugly-plugins medit thunar sakura xmms meld gimp gpicview feh pidgin xmms vlc abiword galculator gnumeric xpdf obconf aspell-en conky gpicview scrot openbox-themes
yaourt -S phatch
esac
#Install extra fonts
echo
echo -n "Install additional fonts? (Y/n) "
read Keypress6
case "$Keypress6" in
[Nn])
break
powerpill -S ttf-bitstream-vera ttf-dejavu ttf-ms-fonts
esac
echo
echo "All programs and packages are updated and installed. "
#Import config files
echo
echo -n "Import configuration file backups? (Y/n) "
read Keypress7
case "$Keypress7" in
[Nn])
echo
echo "This script is complete. Exiting... "
exit
ping 192.168.1.200 -c 1 > /dev/null #2>&1
if [ $? -eq 0 ] ; then
echo
echo "Connecting to server... "
else
echo
echo "The server was not found at 192.168.1.200. "
echo "Please re-run script when server is connected "
echo "or set configurations manually. Exiting... "
exit
fi
esac
echo "Downloading ArchBoxBak.tar.gz... "
scp [email protected]:ArchBoxBak.tar.gz /
echo
echo -n "Install config files automatically? (Y/n) "
read Keypress8
case "$Keypress8" in
[Nn])
echo
echo "This script is complete. Exiting... "
exit
echo "Extracting ArchBoxBak.tar.gz... "
tar -xzf /ArchBoxBak.tar.gz
esac
echo
echo "Please verify the files were extracted correctly. "
echo "Use <ctrl><alt><f2-f7> to open a new console. "
echo "Press any key to continue. "
read Keypress9
case "$Keypress9" in
break
esac
echo
echo -n "Remove ArchBoxBak.tar.gz? (Y/n)"
read Keypress10
case "$Keypress10" in
[Nn])
break
rm /ArchBoxBaks.tar.gz
esac
echo
echo "This install is complete."
exit
Please, if you feel so inclined, take a look and give some feedback. Both scripts are working but I do have an appreciation for doing things the "right" way, so if you see something that could be improved let me know. I think the next step will be to ask for inputs for file name, location, things like that so that it will be usable for anyone.
-monstermudder78fukawi2 wrote:
Make the backup script shorter, faster and save having the temporary holding file...
#!/bin/bash
tar cvzf - /home/casey/.bashrc /home/casey/.conkyrc /home/casey/.xinitrc /home/casey/scripts /home/casey/.keytouch2 /home/casey/.config | ssh [email protected] 'cat - > /home/casey/ArchBoxBak.tar.gz'
Just a note - in your original script, you're calling tar with the cvf options, (ie, without the z option), but you're naming the file with a .gz extension. Either use the 'z' option to compress it, or just name it .tar extension
I think either I am not understanding something or you might have missed it, but in my post I think I am using 'z':
#!/bin/bash
tar cvzf - /home/casey/.bashrc
fukawi2 wrote:
Also, IMHO, it's good to use variables and absolute paths. Personally, I'd expand the script to something like this:
#!/bin/bash
USERNAME='casey'
SERVER='192.168.1.200'
SERVER_FILE='/home/casey/ArchBoxBak.tar.gz'
TAR='/bin/tar'
SSH='/usr/bin/ssh'
$TAR cvzf - /home/casey/.bashrc /home/casey/.conkyrc /home/casey/.xinitrc /home/casey/scripts /home/casey/.keytouch2 /home/casey/.config | $SSH ${USERNAME}@${SERVER} "cat - > ${SERVER_FILE}"
Doesn't really offer any great advantages in this instance (unless the PATH var isn't set properly at run time), but if you expanded the script out to do multiple things with the file on the server (chmod for example), then using the variables means you only have to update it in one place if you want to change the filename in the future.
Thanks for the pointer. This was an idea that crossed my mind but I didn't know how to do it easily and then I moved on.
fukawi2 wrote:Overall, pretty good for a first shot
Thanks for taking the time to look it over -
How do i create a backup script
please how do i create a backup script to run full backup
user9106453 wrote:
please how do i create a backup script to run full backupIs there a reason that you don't want to use the one provided with the installation ? -
NT 의 OCOPY 를 이용한 HOT BACKUP SCRIPT
제품 : ORACLE SERVER
작성날짜 : 2002-04-25
NT 의 OCOPY 를 이용한 HOT BACKUP SCRIPT
========================================
PURPOSE
다음은 NT에서 OCOPY를 이용하여 HOT BACKUP을 하는 SCRIPT를
제공한다.
Examples
1) <Batch file 1 >
Online_backup_data 라는 batch file 은 다음처럼 이루어질 수 있다.
svrmgr23 @d:\temp\begin_user_backup.sql
ocopy73 d:\orant\database\usr1orcl.ora d:\temp\usr1orcl.bck
svrmgr23 @d:\temp\end_user_backup.sql
svrmgr23 @d:\temp\begin_SYS_backup.sql
ocopy73 d:\orant\database\SYS1orcl.ora d:\temp\SYS1orcl.bck
svrmgr23 @d:\temp\end_SYS_backup.sql
svrmgr23 @d:\temp\begin_temp_backup.sql
ocopy73 d:\orant\database\TMP1orcl.ora d:\temp\TMP1orcl.bck
svrmgr23 @d:\temp\end_temp_backup.sql
로 만들 수 있다.
이 때 begin_user_backup.sql file 내용은
connect system/manager
alter tablespace user_data begin backup;
exit; 이고 ,
또 end_user_backup.sql file 내용은
connect system/manager
alter tablespace user_data end backup;
exit;
로 구성되어야 한다.
2) 또는 BATCH FILE 을 다음처럼 구성할 수 있다.
svrmgr23 @d:\temp\backup.sql
backup.sql script 내용은 다음과 같이 작성한다.
connect system/manager
alter tablespace user_data begin backup;
host ocopy73 e:\orant\database\usr1orcl.ora d:\tmp\usr1orcl.bck
alter tablespace user_data end backup;
alter tablespace SYSTEM begin backup;
host ocopy73 e:\orant\database\SYS1orcl.ora d:\tmp\SYS1orcl.bck
alter tablespace SYSTEM end backup;
alter tablespace ROLLBACK_DATA begin backup;
host ocopy73 e:\orant\database\RBS1orcl.ora d:\tmp\RBS1orcl.bck
alter tablespace ROLLBACK_DATA end backup;
alter tablespace TEMPORARY_DATA begin backup;
host ocopy73 e:\orant\database\TMP1orcl.ora d:\tmp\TMP1orcl.bck
alter tablespace TEMPORARY_DATA end backup;
exit;
Reference Documents
-------------------- -
I mean as we write a backup script to take backup of whole day working for Hr db like i use the following script to take backup of one user
for /f "tokens=2,3,4 delims=/ " %%a in ('date /t') do set fdate=%%a%%b%%c
for /f "tokens=1,2,3,4,5 delims=: " %%a in ('time /t') do set ftime=%%a%%b%%c%%d%%e
exp userid=HR/HR@dummy file=D:\BACKUP\backup%fdate%%ftime%.dmp log=D:\BACKUP\backup%fdate%%ftime%.log
I made this batch file to take backup of my hr schema but it take backup of whole day my problem is i want to take backup of every hour how to achieve this please help me.i want to take backup of every hour how to achieve this please help me.
for that you need to use one of the proper backup method : User Managed / RMAN.
http://download.oracle.com/docs/cd/E11882_01/backup.112/e10642/part_int.htm#sthref10 -
Launch daemon for svn backup script not working
Hi,
I would like to set up an automatic backup for our subversion repository and I therefore wrote a simple script. The script (see below) works fine if it's started in Terminal (with sudo), but if it is run as a launch daemon the svnsync command inside the script doesn't seem to be called.
Here is the backup script:
#!/bin/sh
datestamp=`date +'%Y-%m-%d'`
echo ========================== >> /Library/Logs/Backup/svnsync.log
echo $datestamp >> /Library/Logs/Backup/svnsync.log
svnsync synchronize file:///Volumes/HD-Backup-Server/svn/svn-mirror >> /Library/Logs/Backup/svnsync.log
And this is the plist file inside /Library/LaunchDaemons:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>de.namos.svnBackup</string>
<key>ProgramArguments</key>
<array>
<string>/opt/subversion/bin/svnbackup.sh</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>StartInterval</key>
<integer>3600</integer>
</dict>
</plist>
The log file just contains the "=" characters and the current date. Unlike the direct call from the terminal app there is no output from svnsync in the log file.
==========================
2011-04-30
==========================
2011-04-30
==========================
2011-04-30
==========================
2011-04-30
I would greatly appreciate any help as well as general ideas and considerations related to the problem.
Kind regards,
Juergenwbadmin start systemstatebackup -backupTarget:$backdir -[quiet]"[quiet]"? I guess you should remove the bracketswbadmin start systemstatebackup -backupTarget:$backdir -quiet
-
Oracle Hot Backup Script Windows Server 2003
Hello,
Does anyone here have a working Oracle 10I database hot backup script for Windows Server 2003? If so can you please post it here.
Thanks.Here is a basic batch script I have used for a hot backup of Oracle databases using RMAN
Will just need to update some locations based on you environment just check all the comments and change what you need to but this can be scheduled to run regularly through the windows scheduler for database backups.
This will take a hot backup and backup the archive logs.
Let me know if you have any quesitons.
REM #####################################################################
REM # Name: rman_hot_backup_dsk.bat
REM #
REM # Description:
REM #
REM # Generic Hot backup script that accepts the SID
REM #
REM # Parameters: Instance Name, backup level
REM #
REM #####################################################################
REM #
REM # Check if SID was Passed
if (%1)==() goto USAGE
if (%2)==() goto USAGE
REM # assign ORACLE_SID to passed SID
set ORACLE_SID=%1
REM # Set the hot backup level 0-full 1-incremental
set LEVEL=%2
REM # export the page list
set [email protected]
REM # assign a date we can use as part of the logfile
set DTE=%date:~-4%%date:~4,2%%date:~7,2%_%time:~0,2%%time:~3,2%%time:~6,2%
REM # Take the spaces out of the date string so we can use in our file name
set DTE=%DTE: =%
REM # set the script location
REM # Set location of where you will put script
set SCRIPTLOC=C:\app\oracle\scripts
cd %SCRIPTLOC%
REM # Set the Temporary command file that we will write our rman script to
set CMDFILE=%SCRIPTLOC%\%ORACLE_SID%_rman_hot_backup_dsk.cmd
REM # Remove the temporary file if it exists
del /q %CMDFILE%
REM # Set the logfile directory
REM # Change based on where you want the backup logs to go
set LOGPATH=W:\ORACLE_BACKUP\logs
set LOGFILE=%ORACLE_SID%_rman_hot_backup_dsk_%DTE%.log
set LOG=%LOGPATH%\%LOGFILE%
REM # Set the path of the backup location
REM # Change based on disk pach for you disk based backups
set BACKLOC=\\VirtualBox\ORA_ITS03P\ORACLE_BACKUP\%ORACLE_SID%
REM # Lets set the ORACLE_HOME for the host
REM # Set to your actual ORACLE_HOME location
set ORACLE_HOME=C:\app\oracle\product\10.2.0\db_1
# Set the rest of the Oracle Environment
# based on our ORACLE_HOME
set LIBPATH=%ORACLE_HOME%/lib
set LD_LIBRARY_PATH=%ORACLE_HOME%/lib
set TNS_ADMIN=%ORACLE_HOME%/network/admin
REM #set ORA_NLS10=%ORACLE_HOME%/nls/data
REM Set our PATH with the ORACLE_HOME so that we have a good
REM clean environment to work with
set PATH=%ORACLE_HOME%/bin;%ORACLE_HOME%/OPatch;%PATH%
REM # Write Temporary command file for RMAN backup
echo # configure retention policy >> %CMDFILE%
echo CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 14 DAYS ; >> %CMDFILE%
echo # >> %CMDFILE%
echo # lets start clean for our hot backup by doing full crosschecks >> %CMDFILE%
echo change archivelog all crosscheck ; >> %CMDFILE%
echo crosscheck backup of database; >> %CMDFILE%
echo crosscheck backup of controlfile; >> %CMDFILE%
echo # >> %CMDFILE%
echo # delete all expired and obsolete backups >> %CMDFILE%
echo allocate channel for maintenance type disk ; >> %CMDFILE%
echo delete noprompt expired archivelog all ; >> %CMDFILE%
echo delete noprompt expired backup ; >> %CMDFILE%
echo delete noprompt obsolete ; >> %CMDFILE%
echo # >> %CMDFILE%
echo # Configure control file for auto backup >> %CMDFILE%
echo configure controlfile autobackup on ; >> %CMDFILE%
echo CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '%BACKLOC%\%ORACLE_SID%_controlfile_%%F' ; >> %CMDFILE%
echo # >> %CMDFILE%
echo # Configure default device type here we use disk and set parallelism to 2 >> %CMDFILE%
echo configure default device type to disk ; >> %CMDFILE%
echo configure device type disk parallelism 2 ; >> %CMDFILE%
echo # >> %CMDFILE%
echo # Must format the default channel for the device type disk >> %CMDFILE%
echo # other wise tmp area in creating pieces will be done in >> %CMDFILE%
echo # the $ORACLE_HOME/dbs directory >> %CMDFILE%
echo CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT = '%BACKLOC%\%ORACLE_SID%_hot_%%U' ; >> %CMDFILE%
echo # >> %CMDFILE%
echo # Configure our retention policy for this database >> %CMDFILE%
echo configure retention policy to recovery window of 14 days ; >> %CMDFILE%
echo # >> %CMDFILE%
echo # Let configure our channels for our backup >> %CMDFILE%
echo # Channel 1 disk and we indicate where it goes not taking the default >> %CMDFILE%
echo configure channel 1 device type disk MAXPIECESIZE = 4G format '%BACKLOC%\%ORACLE_SID%_hot_%%U' ; >> %CMDFILE%
echo # Channel 2 disk and we indicate where it goes not taking the default >> %CMDFILE%
echo configure channel 2 device type disk MAXPIECESIZE = 4G format '%BACKLOC%\%ORACLE_SID%_hot_%%U' ; >> %CMDFILE%
echo # >> %CMDFILE%
echo # Backup our database with compression on >> %CMDFILE%
echo backup as compressed backupset incremental level %LEVEL% tag hot_%LEVEL%_%DTE% DATABASE ; >> %CMDFILE%
echo # >> %CMDFILE%
echo # Backup our archive log files that have not been backed up >> %CMDFILE%
echo backup as compressed backupset format '%BACKLOC%\%ORACLE_SID%_Archive_%%d_%%s_%%p_%%t' archivelog all not backed up 1 times ; >> %CMDFILE%
echo # >> %CMDFILE%
echo # Backup Control file for standby in case needed >> %CMDFILE%
echo backup current controlfile for standby ; >> %CMDFILE%
echo # >> %CMDFILE%
echo # let put a controlfile to trace >> %CMDFILE%
echo sql 'ALTER DATABASE BACKUP CONTROLFILE TO TRACE' ; >> %CMDFILE%
REM # Run the RMAN backup without using the recovery catalog
%ORACLE_HOME%\bin\rman target=/ nocatalog cmdfile=%CMDFILE% msglog=%LOG%
REM # Remove our temporary command file
del /q %CMDFILE%
REM # Mail Archive backup log
REM # This relies on the free bmail utility
bmail -date -m %LOG% -f [email protected] -s <smtpserver> -t %PAGE_LIST% -a "HOT Backup results"
REM # Goto end of script as we are done
goto END
:USAGE
echo "Must Pass ORACLE_SID and hot backup level as parameters."
goto END
:END -
Help Needed With a Backup Script
I am writing a DNS server backup script with additional options.
Backing Up DNS Server Daily
Create a folder based on current date
Copy the backup from source to newly created folder based on date
Complicated part (well, for me anyway :) )
keeping current month's backup (30 different copies/Folder of backup for each day)
Create a folder every calender month and and copy all 30 copies of backups within this folder
Email Results of copying process either success or failed
So Far i have the following which covers half of what is required!
$date = Get-Date -Format yyyyMMdd
New-Item C:\dnsbk\DNSBackup$date -ItemType Directory
$1st = Export-DnsServerZone -Name test.ac.uk -Filename backup\test.ac.uk.bk
$2nd = Export-DnsServerZone -Name _msdcs.test.ac.uk -FileName backup\_msdcs.test.ac.uk.bk
$source = "C:\windows\system32\dns\*"
$destination = "C:\dnsbk\DNSBackup$date"
$copy = Copy-Item -Recurse $source $destination
$successSubject = "Backup Completed Successfully"
$SuccessBody = "$1st,$2nd,$copy" <<<<<< This does not work >>>>>
Send-MailMessage -From "[email protected]" -To "[email protected]" -Subject $successSubject -SmtpServer 192.168.0.1 -Body $SuccessBodyHi IM3th0,
If you want to confirm whether the copy operation run successfully and pass the result to the variable $SuccessBody, please try the script below:
$copy = Copy-Item -Recurse $source $destination -PassThru -ErrorAction silentlyContinue
if ($copy) { $SuccessBody="copy success" }
else { $SuccessBody="Copy failure"}
Reference from:
how to capture 'copy-item' output
If you want to remove the other 29 copies and keep the lastest one, please filter the 29 copies based on lastwritetime:
$CLEANUP = (Get-DATE).AddDays(-30)
$CLEANUP1 = (Get-DATE).AddDays(-1)
Get-ChildItem | %{
if($_.lastwritetime -gt $CLEANUP -and $_.lastwritetime -lt $CLEANUP1){
Remove-Item $_.fullname -whatif}
If I have any misunderstanding, please let me know.
I hope this helps.
Maybe you are looking for
-
How can we give navigation to go a saved pdf and open it, in obiee report c
I have a requirement for obiee 11g report, that I have to create a report which have a column, whose value should be pdf icon and when we click on that it should we go to saved pdf and open it. Please give me reply as soon as possible. Edited by: 903
-
Hi Experts, i have created a custom program by copying FP_TEST_00 and gave nodialog mode for out parameters which will supress the prompt for printer and that i can run it in background. i just want the data to written to spool. call function 'FP_J
-
Merge data creating duplicate listings
I have a csv database with about 580 records. I've created a template with the correct fields in inDesign, loaded the csv file using merge data, then created the merged document. I get 580 listings of one item like the image below. If there is an err
-
HT204266 How do I submit a review of an app?
I want to submit a review of an app? Where and how?
-
HT1338 i have i mac 7,1 with os x 10.5.8 how i can i update it?
I have I mac 7,1 with OS x 10.5.8 how I can I update it?