Skip to content

Instantly share code, notes, and snippets.

@lajunta
Created November 12, 2010 07:45
Show Gist options
  • Save lajunta/673849 to your computer and use it in GitHub Desktop.
Save lajunta/673849 to your computer and use it in GitHub Desktop.
backup apps
#!/usr/bin/ruby
Backpath = "/backup/apps/dljy"
Now = Time.now
DATE = Now.strftime("%Y-%m-%d")
Dom = Now.mday # Day of month
Dow = Now.wday # Day of week
M = Now.month # Month of the year
W = Now.strftime("%W") # Week of the year
Doweekly = 6 # Saturday
def dljybackup(bkpath)
#exclude tmp&log dir and change dir to /usr/local/railsites
`tar zcfP #{bkpath} --exclude "tmp" --exclude "log" -C /usr/local/railsites zcms/`
end
#Create required directory
#first check backup directory exist?
if Dir[Backpath] == []
`mkdir -p #{Backpath}`
end
#check daily exist?
if Dir["#{Backpath}/daily"] == []
`mkdir -p '#{Backpath}/daily'`
end
#check weekly exist?
if Dir["#{Backpath}/weekly"] == []
`mkdir -p '#{Backpath}/weekly'`
end
#check monthly exist?
if Dir["#{Backpath}/monthly"] == []
`mkdir -p '#{Backpath}/monthly'`
end
#make monthly backup
if Dom=="1"
bkpath=Backpath+"/monthly/dljy.tar.gz"
dljybackup bkpath
end
#make weekly backup
if Dow==Doweekly
bkpath=Backpath+"/weekly/dljy.tar.gz"
dljybackup bkpath
else
bkpath=Backpath+"/daily/dljy.tar.gz"
dljybackup bkpath
end
@lajunta
Copy link
Author

lajunta commented Nov 12, 2010

!/bin/sh

PATH=/var/lib/gems/1.9.1/bin:/usr/local/mongodb/bin:/usr/bin
cd /usr/local/railsites/zcms
unicorn_rails -p 80 -E production -D
exit 0

stop

!/bin/bash

pkill unicorn_rails

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment