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. Thanks madunix
Hi, Try the ff: On 1/25/11 4:31 PM, madunix at 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 basisYes, just use crontab for that. Something like, 30 6 * * * command-or-path-to-script-here to run the command or script everyday 6:30 a.m.> and to keep the last 5days backup on the > box and remove older version than 5days. > Can you point me out.I think the easiest way is to use logrotate. man logrotate for details. HTH, -- - Edwin - mailto:ml2edwin at gmail.com ?Pleasant sayings are a honeycomb, sweet to the soul and a healing to the bones.??Proverbs 16:24
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 at gmail.com <madunix at 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. > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.centos.org/pipermail/centos/attachments/20110125/c1068b41/attachment-0002.html>
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 at 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 at gmail.com <madunix at 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 at centos.org > http://lists.centos.org/mailman/listinfo/centos > >
From: "madunix at gmail.com" <madunix at 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