Current position:  Home > Default > I need help making a backup script

I need help making a backup script

Time:November 30
Advertisement
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.
Advertisement
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...

Backup script

2015-10-11

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 cr

How do I create a automated file backup script?

2015-10-11

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

Parallel Backup script written in python

2015-10-11

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

Unix Backup Script Question

-0001-11-30

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

Schedule backup script ICM

-0001-11-30

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 ba

A decent cold backup script

-0001-11-30

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      alloc

Rman hot backup script  gives error in R12.

-0001-11-30

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. [[email protected] rman_log]# cat UAT_daily_rman_hot_bkp

Install & Backup Scripts - 1st try at scripting

-0001-11-30

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 /

How do i create a backup script

-0001-11-30

please how do i create a backup script to run full backupuser9106453 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 ?Read other 5 answers

NT 의 OCOPY 를 이용한 HOT BACKUP SCRIPT

-0001-11-30

제품 : 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 은 다음처럼 이루어질 수 있다.

Oracle Backup Script

-0001-11-30

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 d

Launch daemon for svn backup script not working

-0001-11-30

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 ins

Oracle Hot Backup Script Windows Server 2003

-0001-11-30

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

Help Needed With a Backup Script

-0001-11-30

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 c

RMAN Backup Script not running in cron tab

-0001-11-30

Hi, I am having rman backup script which is being executed successfully through shell. but when scheduled in cron the script is being called but RMAN commands are not getting executed. i have scheduled cron using oracle user. Attached below the rman

Running same backup script on two different Databases

-0001-11-30

Hello All, I am running same backup script on two different Databases. But output is different. Please give me your feedback. 1) Database 1: OS: AIX DB: 10.1.0.4.0 Script: export ORACLE_SID=sid1 cd $ORACLE_HOME/bin ./rman nocatalog << EOF connect ta

Require backup script which deletes the daily backups after weekly backup

-0001-11-30

Hi, I am new to Oracle administration. I require a backup script which will delete the daily backups (incremental) after weekly backup is taken (full database backup). Currently I use Oracle 10g for one of my production server. My backup strategy is

Win2000/NT hot backup script

-0001-11-30

Can someone provide a basci script for online(hot) backup for Oracle9i(8i) on Windows2000/NT server? we have a online application, and plan to back it up every night. Also, Windows should have administrative tool to schedule the backup by envoking th

RMAN Level 0 backup script

-0001-11-30

Hi All, Required level 0 backup script. We have 10gR2 [10.2.0.4] Production instance, for backup required level 0 script. Regards ShaikShaik wrote: Hi All, Required level 0 backup script. We have 10gR2 [10.2.0.4] Production instance, for backup requi