开发者

How to nightly update a copy folder of main website?

I have a main website, then I have a backup of the main site in another folder on the server to be used if main site goes down I can push traffic to my copy of the main site.

With that said I want to nightly update the copy site with the updated files made to the main site from the prior day's updates to text files and new images. W开发者_开发知识库hat is best method of doing this automatically every 24 hours? I assume a cron script could be created for this need?

Any help would be greatly appreciated.


A cron job calling rsync should be enough play around with their man pages a bit, but this in your crontab should work.

0 0 * * * rsync src target >> log_file


If the data you have is just a set of files (no databases) then rsync would be a good choice. It synchronises two locations on either on the same machine or separate machines. It does however require an rsync daemon to be running on one of the machines or ssh access. SSH access is there by default on most Linux distributions. This won't work on Windows unless you install something like cygwin. If you need any more information then please ask.


Using cronjobs is a good idea, but please keep in mind that sometimes copy won't be enough. For example, if your site has a database connection, you may want to export this data as well. Also please remember that keeping the files on the same machine is worse than making backup to another machine, and than pointing the domain to it in case the whole server stops responding.

I am using the following tools -

  • crontab
  • rsync - copy files securely between machines using SSH.
  • mysqldump - export database tables.


Yes, you can run a cron script... but if the main site goes down, do you really think that another folder on the same server is going to stay up? I don't know about your particular site, but for most sites I would assume that failures are likely to be due to events impacting the server computer, not a particular folder on the server, such as overloading, power outage, disk or other system failure, etc.

As for the implementation of the cron script, you should take a look at rsync, which can synchronize folders both on the same computer or between computers. Another possibility is to store your website in a Subversion repository or other SCM, and simply run an update command periodically. Of course, this requires you to have some form of hosting for the Subversion (or other SCM) repository.

In cron, you can use the abbreviation "@midnight" to indicate that an event should occur at midnight (instead of having to fill out each of the various time fields). See the cron Wikipedia page.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜