Its useful for ruby and rails programmer.sometimes We need our database backup at limited time in travel for that we can do something like this and the idea expanded to include every day schedule of backup.
My first initial thoughts were on Dropbox, I’ve installed the Dropbox client on my no GUI Ubuntu Server, but when I ran the Dropbox the memory usage got doubled and I remove it all together!
“backup Gem”
The backup gem is one great gem with a lot of backup options like databases, storages, compressions.
How to install
Installation is a straight forward like any Ruby Gem:
Type in terminal
- $ gem install backup
or do it through gemfile
Backup Model Generator
backup generate:model –trigger=TRIGGER
Options:
–trigger=TRIGGER
[–config-path=CONFIG_PATH] # Path to your Backup configuration directory
[–databases=DATABASES] # (mongodb, mysql, postgresql, redis, riak)
[–storages=STORAGES] # (cloudfiles, dropbox, ftp, local, ninefold, rsync, s3, scp, sftp)
[–syncers=SYNCERS] # (cloud_files, rsync_local, rsync_pull, rsync_push, s3)
[–encryptors=ENCRYPTORS] # (gpg, openssl)
[–compressors=COMPRESSORS] # (bzip2, gzip, lzma, pbzip2)
[–notifiers=NOTIFIERS] # (campfire, hipchat, mail, presently, prowl, twitter)
[–archives]
[–splitter] # use `–no-splitter` to disable
# Default: true
Generate a Backup model file
Let’s create simple config file with backup generator:
- $ backup generate:model –trigger miguest_backup –databases=”postgresql”
# encoding: utf-8
##
# Backup Generated: miguest_backup
# Once configured, you can run the backup with the following command:
#
# $ backup perform -t miguest_backup [-c ]
#
Backup::Model.new(:miguest_backup, ‘Description for miguest_backup’) do
##
# Split [Splitter]
#
# Split the backup file in to chunks of 250 megabytes
# if the backup file size exceeds 250 megabytes
#
split_into_chunks_of 250
##
# PostgreSQL [Database]
#
database PostgreSQL do |db|
db.name = “my_database_name”
db.username = “my_username”
db.password = “my_password”
db.host = “localhost”
db.port = 5432
# db.socket = “/tmp/pg.sock”
# db.additional_options = [“-xc”, “-E=utf8”]
# Optional: Use to set the location of this utility
# if it cannot be found by name in your $PATH
# db.pg_dump_utility = “/opt/local/bin/pg_dump”
end
##
# FTP (File Transfer Protocol) [Storage]
#
store_with FTP do |server|
server.username = “my_username”
server.password = “my_password”
server.ip = “1.2.3.4”
server.port = 21
server.path = “~/backups/”
server.keep = 5
server.passive_mode = false
end
##
# Bzip2 [Compressor]
#
compress_with Bzip2
end
Fairly be straight forward refinements are needed, usernames, passwords,… After adding all the secret stuff, the backup can be run as easy as:
run the commond from terminal as-
$ backup perform –trigger miguest_backup
backups with whenever Gem
Whenever is a Ruby gem that provides a clear syntax for writing and deploying cron jobs. And this is what I need to schedule the backups to run everyday.
Install
$ gem install whenever
Configure (Wheneverize)
Configure the whenever, but first make sure that we are in backup folder ~/Backup
$ cd ~/Backup
Then create config folder:
$ mkdir config
And then run the command:
$ wheneverize .
go to the directory Open the config/schedule.rb file and add the following:
every 1.day, :at => '4:30 am' do
command "backup perform --trigger miguest_backup"
end
Schedule to crontab
Run whenever with no arguments see the crontab entry this will create:
$ whenever
will display something like this –
30 4 * * * /bin/bash -l -c 'backup perform --trigger miguest_backup'
## [message] Above is your schedule file converted to cron syntax; your crontab file was not updated.
## [message] Run `whenever –help’ for more options.
To write (or update) this job in your crontab, use:
whenever –update-crontab
And that’s it, so what is included:
Backup of postgres database.
Sending compressed backup via FTP.
Scheduled backup every day at 4:30 am.
Nice Blog!!!
It help me a lot in Back Up.
Hi admin, i found this post on 24 spot in google’s search results.
You should reduce your bounce rate in order to rank in google.
This is major ranking factor nowadays. There is very handy wp plugin which can help you.
Just search in google for:
Seyiny’s Bounce Plugin
Awesome issues here. I am very satisfied to peer your article. Thank you a lot and I’m looking ahead to touch you. Will you please drop me a mail?
Thank you for the good writeup. It in truth was once a leisure account it. Look complicated to far added agreeable from you! By the way, how can we communicate?
I have read through numerous nutrients the following. Unquestionably benefit book-marking for revisiting. I’m wondering just how a great deal try out you place to generate this sort of fantastic beneficial website.
Generally I don’t learn post on blogs, however I wish to say that this write-up very pressured me
to take a look at and do it! Your writing style has been surprised me.
Thanks, very nice post.