LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-15-2009, 03:01 AM   #1
ytd
Member
 
Registered: Jan 2009
Posts: 197

Rep: Reputation: 31
HOW TO MAKE backup script LINUX CentOS5 copy data to another machine


How do I make a script and what text do I need to enter in that script in order to copy the data from the local machine to another windows machine ?
The winodws machine has a share space and I want to copy the data from the linux machine each monday, tuesday, wednesday, etc.

I need the text that I need to enter in that script and I also know that I need to create cron jobs to start the back up and the time I need to.

It would be nice if I have some example or if I can have the text here already made.

Thankx in advance.

LE:

EG:

Let's say that the data that needs to be backup is in /var/www/ and I want to backup the data in one server machine (windows) and the name of the windows server machine is backupstorage and the ip is 10.0.0.1

mkdir -p /mnt/ntserver
mount -t cifs //backupstorage/download -o username=myUser,password=myPassword /mnt/backupstorage

How will the script look ?

#! /bin/bash

# Variables
location=/var/www
directory=/*
backuplocation=/mnt/backupstorage

... and then ?

Last edited by ytd; 09-15-2009 at 03:26 AM.
 
Old 09-15-2009, 03:16 AM   #2
vishesh
Member
 
Registered: Feb 2008
Distribution: Fedora,RHEL,Ubuntu
Posts: 661

Rep: Reputation: 66
create a folder in /mnt
#mkdir /mnt/windata

mount your windows share then copy contents to it, in script file do following
root# vi myscript.sh
mount -t cifs //ip_of_windows/sharename /mnt/windata
cp -ar <path of linux data> /mnt/windata


now in cron do entries to execute above given script
#crontab -e
5 12 * * * /root/myscript.sh

Above given entry execute /root/myscript.sh script on every day at time 12.5

thnks
 
Old 09-28-2009, 02:53 AM   #3
ytd
Member
 
Registered: Jan 2009
Posts: 197

Original Poster
Rep: Reputation: 31
Ok, thank you very much. It is working perfect with a few modification. Now please tell me how do I first archive the backup to *tar.gz and then backup the folders. It is 200GB of text files.


LE:

Looks like this command below is much better than the: "cp -ar <path of linux data> /mnt/windata"

tar -cvf /autobackups/home$(date +%y%m%d).tar /home

it creates backup of the entirely /home to /autobackups/home

Last edited by ytd; 09-28-2009 at 03:36 AM.
 
Old 09-28-2009, 06:13 AM   #4
ytd
Member
 
Registered: Jan 2009
Posts: 197

Original Poster
Rep: Reputation: 31
I have arhived the content of the needed directory and after the archive the *.tar archive was the same as the directory itself. It ocupes the same amount of space. Is it a different command to archive more or to archive more compact ?

I arhived 10GB of directorys / subfolders / folders and the archive had the same amount of space, 10GB.

Any hints ?
 
Old 09-28-2009, 07:47 PM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
Add the z flag

tar -czvf /autobackups/home$(date +%y%m%d).tgz /home

http://linux.die.net/man/1/tar
 
Old 09-29-2009, 06:36 AM   #6
ytd
Member
 
Registered: Jan 2009
Posts: 197

Original Poster
Rep: Reputation: 31
chris ftw

OMG it's Chris again !

Oh, why thank you very much Chris. You helped me again.
 
Old 09-29-2009, 09:54 PM   #7
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
No worries; thx for thumbs up/nice comment
 
Old 09-29-2009, 10:18 PM   #8
manwithaplan
Member
 
Registered: Nov 2008
Location: ~/
Distribution: Arch || Sidux
Posts: 393

Rep: Reputation: 45
I use rsync ... I rotate backups with an rsync script. Using a cron job, I have it sync any changes four times a day rotating. In your case, just set the cron for days of the week. And add a mount command into the script.

Here's the script & cron; You can change it to suit your needs

Code:
#!/bin/bash


# -------------- File and directory locations --------------------------
# Assume that the destination volume is mounted. I use an external
# usb disk that mounts automatically when plugged in.
DESTINATION=/media/XTRA/Linux/Funtoo/Home

# Default is to backup my home directory.
SOURCE=/home/manwithaplan

# Other files and directories excluded or included are listed in the
# following file. See "FILTER RULES" and "INCLUDE/EXCLUDE PATTERN RULES"
# sections in the rsync man page for the format of this file.
# Examples are:
# - .mozilla/firefox/eyo8gt4n.default/Cache
# - .opera/cache4
# - .evolution/cache
EXCLUDES=/etc/backup_exclude

# -------------- System commands used here -----------------------------
unset PATH    # to make sure we use the right programs
ECHO=/bin/echo;
RM=/bin/rm;
MV=/bin/mv;
TOUCH=/bin/touch;
RSYNC=/usr/bin/rsync;
MKDIR=/bin/mkdir;

# -------------- Make the snapshot -------------------------------------
# Delete oldest snapshot if it exists.
if [ -d $DESTINATION/snapshot_3 ] ; then
   $RM -rf $DESTINATION/snapshot_3
   $ECHO "Removed old snapshot_3"
fi

# Move existing snapshots back one.
if [ -d $DESTINATION/snapshot_2 ] ; then
   $MV $DESTINATION/snapshot_2 $DESTINATION/snapshot_3
   $ECHO "Created new snapshot_3"
fi

if [ -d $DESTINATION/snapshot_1 ] ; then
   $MV $DESTINATION/snapshot_1 $DESTINATION/snapshot_2
   $ECHO "Created new snapshot_2"
fi

if [ -d $DESTINATION/snapshot_0 ] ; then
   $MV $DESTINATION/snapshot_0 $DESTINATION/snapshot_1
   $ECHO "Created new snapshot_1"
fi

# rsync from SOURCE to DESTINATION.

if [ -d $DESTINATION/snapshot_1 ] ; then
   $ECHO "Creating snapshot_0 based on snapshot_1 on $DESTINATION"
   $RSYNC -a -v --delete    \
        --exclude-from=$EXCLUDES           \
        --link-dest=$DESTINATION/snapshot_1    \
        $SOURCE $DESTINATION/snapshot_0/
else
   $ECHO "Creating a new snapshot_0 on $DESTINATION"
   $MKDIR $DESTINATION/snapshot_0
   $RSYNC -a -v --delete    \
        --exclude-from=$EXCLUDES           \
        $SOURCE $DESTINATION/snapshot_0/
fi
$ECHO "rsync exit code is "$?

# update the mtime of snapshot_0 to reflect the snapshot time
$TOUCH $DESTINATION/snapshot_0
Cron:
Code:
0 8,12,17,21 * * * ~/bin/make_snapshot.sh &>/dev/null
This keeps a rotating copy 4 times a day of my home directory, this way I can revert back to any timestamp throught the day.

Last edited by manwithaplan; 09-29-2009 at 10:20 PM.
 
Old 09-30-2009, 02:54 PM   #9
ytd
Member
 
Registered: Jan 2009
Posts: 197

Original Poster
Rep: Reputation: 31
ty man, but I already build up the script. It's working perfect. 250GB arhived in 35GB cuz of chris. He helped me as you see. He helped me at informix server too, he is a nice lil buddy. Thankx for your comment too, can be needed for other users too. ;-)

good luck y`all.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy and paste data on same linux machine from windows netwrok icna Linux - Networking 2 07-08-2009 03:18 AM
copy terabyte of data from one machine to another ufmale Linux - Newbie 3 05-16-2008 01:17 AM
howto copy & backup LARGE amount of data edenCC Linux - Server 5 12-16-2007 10:02 AM
backup files, tar, do i need to make a copy dtra Linux - Software 3 05-10-2005 09:52 PM
error in backup script, deleted almost all data :( ash4stuff Linux - Software 0 06-11-2004 07:58 AM


All times are GMT -5. The time now is 01:02 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration