LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 11-30-2006, 04:38 AM   #1
Swakoo
Member
 
Registered: Apr 2005
Distribution: Red Hat / Fedora / CentOS
Posts: 508

Rep: Reputation: 30
Doing backup of servers scripts using tar/gzip/scp/rm


Hi guys,

I am looking to backup my scripts onto a backup server, thus creating a 7 days repository script database kind of thing.

But how do I pipe the entire command in one line? What I want to achieve is to tar the selected directory, gzip it, scp over to the backup server and then rm it from the web server.

Reason being this server that I am backing up, is kind of a staging server and thus space is pretty low. So I was wondering can I do it all in one shot. I have 7 folders each easily 4-5GB to backup.
 
Old 11-30-2006, 05:28 AM   #2
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
Do you expect to have one tar file per backup?

What you might do is have a script which creates a tar backup file with the day name in the filename, then copy that across to the remote machine, overwriting an old file if necessary.

tar can compress archives as it makes them, no need for a separate step for this. You should configure ssh to use public key authentication to allow remote login without password for the backup user. You can then use scp from a script to do the file transfer.

Something like this:
Code:
#!/bin/bash
cd /path/to/files/to/backup
backup_file="backup_$(date +%a).tar.gz"
tar zcf "$backup_file" * && 
  scp "$backup_file" remoteuser@remotehost:/path/to/backups &&
  rm * &&
  echo "all was OK" ||
  echo "error making $backup_file" |mailx -s "backup error" backupadmin@host.com
For this sort of thing to work, you have some setup to do:
  • mail delivery must be working
  • mailx must be installed
  • ssh public key auth must be set up (for scp)
  • the rm command must be correct!
 
Old 12-01-2006, 01:17 AM   #3
Swakoo
Member
 
Registered: Apr 2005
Distribution: Red Hat / Fedora / CentOS
Posts: 508

Original Poster
Rep: Reputation: 30
yah one tar file per backup.

i was hoping to find a way to delete the tar files on the fly right after i send them over to the backup server as the space available is not enough - by using the | (what you call this?)

I guess I just have to split the commands up for now. hmm
 
Old 12-01-2006, 05:51 AM   #4
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
It is not the unix way for there to be one tool to rule them all. Almost all tasks of this type use more than one tool.

If you would consider a slightly different scheme, rsync might be better suited to your needs.
 
Old 12-05-2006, 02:09 AM   #5
Swakoo
Member
 
Registered: Apr 2005
Distribution: Red Hat / Fedora / CentOS
Posts: 508

Original Poster
Rep: Reputation: 30
i've thought of rsync but was thinking that i don't need to sync, just need to maintain a 7days backup on another machine.


the only reason why i am thinking of this is because of the lack of hdd space to hold the tar files while scp-ing.

think i better solve the root of the problem first: the space constraint
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to use other charsets with tar/gzip darchon Linux - Newbie 2 09-25-2006 07:31 AM
When to use tar , gzip and tar+gzip ? tofee Linux - Newbie 4 03-31-2006 05:59 AM
tar and gzip c0c0deuz Linux - General 2 10-31-2002 03:04 PM
dd, tar and gzip nabil Linux - General 3 01-18-2002 04:51 PM
Need Serious Help With Tar And Gzip!! Please! rootlinux Linux - General 2 12-16-2001 01:39 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 05:36 AM.

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
Open Source Consulting | Domain Registration