Linux Archive

Linux Archive (http://www.linux-archive.org/)
-   CentOS (http://www.linux-archive.org/centos/)
-   -   backup script (http://www.linux-archive.org/centos/480823-backup-script.html)

Nelson 01-25-2011 07:45 AM

backup script
 
You could create a script and have a variable date --date="5 days ago" append to your tar file and after that, combine it with if syntax. If match, then rm.


HTH


On Tue, Jan 25, 2011 at 3:31 PM, madunix@gmail.com <madunix@gmail.com> wrote:

I want to create bash script to have a zip copy from a website running

on linux /var/www/htdocs/* local on the same box on different

directory

I am thinking to do a local backup using crontab (snapshot my web)

tar -cvzf /tmp/website-$(date +%Y%m%d-%H%M).tgz /var/www/htdocs/*

This command will create a file /tmp/website-20110101-1459.tgz

I want it run on daily basis and to keep the last 5days backup on the

box and remove older version than 5days.

Can you point me out.


_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos

"madunix@gmail.com" 01-25-2011 07:56 AM

backup script
 
Am thinking to have this in my script

#!/bin/bash
tar -cvzf /tmp/website-$(date +%Y%m%d-%H%M).tgz /var/www/htdocs/*
find /tmp/website/website*.tgz -ctime +5 -exec rm {} ; # removes
older then 5 days

crontab it
30 6 * * * /mypath/myscript

On Tue, Jan 25, 2011 at 10:45 AM, Nelson <ntserafica@gmail.com> wrote:
> You could create a script and have a variable date --date="5 days ago"
> append to your tar file and after that, combine it with if syntax. If match,
> then rm.
>
> HTH
>
> On Tue, Jan 25, 2011 at 3:31 PM, madunix@gmail.com <madunix@gmail.com>
> wrote:
>>
>> I want to create bash script to have a zip copy from a website running
>> on linux /var/www/htdocs/* local on the same box on different
>> directory
>> I am thinking to do a local backup using crontab (snapshot my web)
>> tar -cvzf /tmp/website-$(date +%Y%m%d-%H%M).tgz /var/www/htdocs/*
>> This command will create a file /tmp/website-20110101-1459.tgz
>> I want it run on daily basis and to keep the last 5days backup on the
>> box and remove older version than 5days.
>> Can you point me out.
>>
>
> _______________________________________________
> CentOS mailing list
> CentOS@centos.org
> http://lists.centos.org/mailman/listinfo/centos
>
>
_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos

Cameron Kerr 01-25-2011 04:00 PM

backup script
 
On 25/01/11 21:56, madunix@gmail.com wrote:
> Am thinking to have this in my script
>
> #!/bin/bash
> tar -cvzf /tmp/website-$(date +%Y%m%d-%H%M).tgz /var/www/htdocs/*
> find /tmp/website/website*.tgz -ctime +5 -exec rm {} ; # removes
> older then 5 days

That should do in your case. Though, in general, you would prefer the
following (because, in the general case, that glob could match a _lot_
of things, though in _your_ case, it should be fine).

find /tmp/website/ -name website*.tgz -ctime +5 -exec rm {} ;

Also, from a security standpoint (especially if your website contains
things private materials the webserver would not serve), you should use
umask to change the default permissions the archive is assigned. You can
set this temporarily as follows:

(umask 077; tar ....)

The (...) construct defines a _subshell_. A umask specifies the mode
bits to clear on a new file, so 077 causes new files to be created as
rw-------. Umask is a property inherited from parent process to child
processes, and is in effect until either changed or the parent proces
(the shell, typically) ends.

The umask _command_ (actually, _shell-internal_ command) affects the
umask of the shell process, which causes the tar child process to see
the change). To prevent subsequent processes also getting that same,
restrictive, umask, I've used a sub-shell (the round-brackets), to limit
the scope of the umask effect to just the tar command.

PS. You're not really keeping your website backups in /tmp, are you?
_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos

John Doe 01-25-2011 04:10 PM

backup script
 
From: "madunix@gmail.com" <madunix@gmail.com>

> I want to create bash script to have a zip copy from a website running
> on linux /var/www/htdocs/* local on the same box on different
> directory
> I am thinking to do a local backup using crontab (snapshot my web)
> tar -cvzf /tmp/website-$(date +%Y%m%d-%H%M).tgz /var/www/htdocs/*
> This command will create a file /tmp/website-20110101-1459.tgz
> I want it run on daily basis and to keep the last 5days backup on the
> box and remove older version than 5days.

A quick way to do it is to use the day of the week:
website-$(date +%u).tgz
It will automaticaly keep the last 7 days...
Otherwise, you will have to use date calculations...

JD



_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos

"madunix@gmail.com" 01-28-2011 08:20 AM

backup script
 
Should I add to my tar the following option
-p, --preserve-permissions
extract all protection information
tar -cvzfp ......

Thanks

On Tue, Jan 25, 2011 at 7:10 PM, John Doe <jdmls@yahoo.com> wrote:
> From: "madunix@gmail.com" <madunix@gmail.com>
>
>> I want to create bash script to have a zip copy from a website running
>> on *linux /var/www/htdocs/* local on the same box on different
>> directory
>> I am *thinking to do a local backup using crontab (snapshot my web)
>> tar -cvzf */tmp/website-$(date +%Y%m%d-%H%M).tgz /var/www/htdocs/*
>> This command will *create a file /tmp/website-20110101-1459.tgz
>> I want it run on daily basis and *to keep the last 5days backup on the
>> box and remove older version than *5days.
>
> A quick way to do it is to use the day of the week:
> *website-$(date +%u).tgz
> It will automaticaly keep the last 7 days...
> Otherwise, you will have to use date calculations...
>
> JD
>
>
>
> _______________________________________________
> CentOS mailing list
> CentOS@centos.org
> http://lists.centos.org/mailman/listinfo/centos
>
_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos

01-28-2011 02:33 PM

backup script
 
madunix@gmail.com wrote:
> Should I add to my tar the following option
> -p, --preserve-permissions
> extract all protection information
> tar -cvzfp ......
>
> Thanks
>
> On Tue, Jan 25, 2011 at 7:10 PM, John Doe <jdmls@yahoo.com> wrote:
> > From: "madunix@gmail.com" <madunix@gmail.com>
> >
> >> I want to create bash script to have a zip copy from a website running
> >> on *linux /var/www/htdocs/* local on the same box on different
> >> directory
> >> I am *thinking to do a local backup using crontab (snapshot my web)
> >> tar -cvzf */tmp/website-$(date +%Y%m%d-%H%M).tgz /var/www/htdocs/*
> >> This command will *create a file /tmp/website-20110101-1459.tgz
> >> I want it run on daily basis and *to keep the last 5days backup on the
> >> box and remove older version than *5days.
> >
> > A quick way to do it is to use the day of the week:
> > *website-$(date +%u).tgz
> > It will automaticaly keep the last 7 days...
> > Otherwise, you will have to use date calculations...

I hope I'm not duplicating something someone has already said --
/tmp may not be the best possible choice for backups. A reboot
could potentially "help" by cleansing that directory. Off-host
copies (eg, scp website-20110101-1459.tgz fred@otherhost:/home/fred/backups/)
would address a number of risks.
--
Charles Polisher

_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos

"madunix@gmail.com" 01-28-2011 04:19 PM

backup script
 
I have reallocated it to /home
thx

On Fri, Jan 28, 2011 at 5:33 PM, <cpolish@surewest.net> wrote:
> madunix@gmail.com wrote:
>> Should I add to my tar the following option
>> *-p, --preserve-permissions
>> * * * * * * * extract all protection information
>> tar -cvzfp ......
>>
>> Thanks
>>
>> On Tue, Jan 25, 2011 at 7:10 PM, John Doe <jdmls@yahoo.com> wrote:
>> > From: "madunix@gmail.com" <madunix@gmail.com>
>> >
>> >> I want to create bash script to have a zip copy from a website running
>> >> on *linux /var/www/htdocs/* local on the same box on different
>> >> directory
>> >> I am *thinking to do a local backup using crontab (snapshot my web)
>> >> tar -cvzf */tmp/website-$(date +%Y%m%d-%H%M).tgz /var/www/htdocs/*
>> >> This command will *create a file /tmp/website-20110101-1459.tgz
>> >> I want it run on daily basis and *to keep the last 5days backup on the
>> >> box and remove older version than *5days.
>> >
>> > A quick way to do it is to use the day of the week:
>> > *website-$(date +%u).tgz
>> > It will automaticaly keep the last 7 days...
>> > Otherwise, you will have to use date calculations...
>
> I hope I'm not duplicating something someone has already said --
> /tmp may not be the best possible choice for backups. A reboot
> could potentially "help" by cleansing that directory. Off-host
> copies (eg, scp website-20110101-1459.tgz fred@otherhost:/home/fred/backups/)
> would address a number of risks.
> --
> Charles Polisher
>
> _______________________________________________
> CentOS mailing list
> CentOS@centos.org
> http://lists.centos.org/mailman/listinfo/centos
>
_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos

Keith Roberts 01-28-2011 04:44 PM

backup script
 
On Fri, 28 Jan 2011, madunix@gmail.com wrote:


To: CentOS mailing list <centos@centos.org>
From: "madunix@gmail.com" <madunix@gmail.com>
Subject: Re: [CentOS] backup script

I have reallocated it to /home
thx

On Fri, Jan 28, 2011 at 5:33 PM, <cpolish@surewest.net> wrote:

madunix@gmail.com wrote:

Should I add to my tar the following option
*-p, --preserve-permissions
* * * * * * * extract all protection information
tar -cvzfp ......

Thanks

On Tue, Jan 25, 2011 at 7:10 PM, John Doe <jdmls@yahoo.com> wrote:
> From: "madunix@gmail.com" <madunix@gmail.com>
>
>> I want to create bash script to have a zip copy from a website running
>> on *linux /var/www/htdocs/* local on the same box on different
>> directory
>> I am *thinking to do a local backup using crontab (snapshot my web)
>> tar -cvzf */tmp/website-$(date +%Y%m%d-%H%M).tgz /var/www/htdocs/*
>> This command will *create a file /tmp/website-20110101-1459.tgz
>> I want it run on daily basis and *to keep the last 5days backup on the
>> box and remove older version than *5days.
>
> A quick way to do it is to use the day of the week:
> *website-$(date +%u).tgz
> It will automaticaly keep the last 7 days...
> Otherwise, you will have to use date calculations...


I hope I'm not duplicating something someone has already said --
/tmp may not be the best possible choice for backups. A reboot
could potentially "help" by cleansing that directory. Off-host
copies (eg, scp website-20110101-1459.tgz fred@otherhost:/home/fred/backups/)
would address a number of risks.


Hi Charles.

You might find this php script I wrote handy:

http://forums.fedoraforum.org/showthread.php?t=248436

I use a seperate 500GB drive just for storing backups of
various things I don't want to loose. Then at certain
intervals (ie when I think needed), I burn the backups to CD
or DVD - just to be extra safe!


Most of my backup scripts are run by cron jobs overnight.

Kind Regards,

Keith Roberts

-----------------------------------------------------------------
Websites:
http://www.karsites.net
http://www.php-debuggers.net
http://www.raised-from-the-dead.org.uk

All email addresses are challenge-response protected with
TMDA [http://tmda.net]
-----------------------------------------------------------------_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos

01-28-2011 04:49 PM

backup script
 
madunix@gmail.com wrote:
> I have reallocated it to /home
> thx
Please stop top posting.

Relocated it to /home, as in /home/backup? Don't clutter your base
directories, that's very bad practice.

mark

_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos

"madunix@gmail.com" 01-28-2011 05:03 PM

backup script
 
home folder for backup /backup

On Fri, Jan 28, 2011 at 7:49 PM, <m.roth@5-cent.us> wrote:
> madunix@gmail.com wrote:
>> I have reallocated it to /home
>> thx
> Please stop top posting.
>
> Relocated it to /home, as in /home/backup? Don't clutter your base
> directories, that's very bad practice.
>
> * * * mark
>
> _______________________________________________
> CentOS mailing list
> CentOS@centos.org
> http://lists.centos.org/mailman/listinfo/centos
>
_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos


All times are GMT. The time now is 09:59 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.