Nov 14

AWS automated ebs snapshots

It is hard to take ebs backup manually each day as system administrator should log in to account daily. This bash script gives the power to automate that process. This automated ebs snapshots generating script reduce administrative task such it can defined how long backup should be kept on AWS account by configuring backup retention period, so Script automatically remove old backups for you. Also you add “cost center values” and “tag”  to the snapshot, this could be useful to identify it and calculate snapshot storage cost later.

Pre Requirements

1) Script is runs on Linux environment

you can keep small EC2 for this, if you don’t have one.

2) Install AWS CLI

please refer this http://docs.aws.amazon.com/cli/latest/userguide/installing.html

3) Configure IAM credentials

Please refer above doc. It will guide you how to do it properly.
** IAM should have permission to create and delete snapshots at least.

Below is full script with sample cron job. I have explained code in detail at the end.

 


 

Bash script explanation.

retention_days –> How long back should be kept on. Remember AWS will bill you for this. So keep retention days as short as possible.
logfile –> script output, kind of debug
volume_info –> EC2 volume ID are kept here for instance named “prod3”
snapshot_info –> Sanpshot ID are kept here for instance named “prod3”

instance_id –> unique ID of the EC2 instance.
os_vol,data_vol –> instance has 2 volume you can define any amount of volumes. example instance was named as “prod3”. so changed that as well.

os_cs_output –> text base (you can see command is append with “–output text” ) output result after creating snapshot. This is for the volume which contains OS. you have to create other volumes if there any. for example I create separate variable for data volume (data_cs_output). cs stands for “create snaphost” 🙂
os_snapshot_id –> grab the snapshot ID.
os_ct_output –> tag the snapshot with cost center value, we already have snapshot ID. This is extra step. you can skip If you wish. ct stands for “create tag”

Now time for delete old snapshots

Empty the volume_info file first. and then insert all volume ID to it.

Empty the snapshot_info file and insert all snapshot created for volumes mentioned on volume_info file.

 

I feels, I explain a lot in here. Do comment here if you have any doubt.

 

Nov 11

Fixed – missing ifcfg-eth0 in Linux

After fresh Linux installation, specially on  virtual environment such as VM Ware, VirtualBox etc , interface configuration file may be missing on the system. Here I’m going to guide how to fix missing ifcfg-eth0 or network interface configuration file in Linux.

1) Find available physical interfaces

Following command will output all connected physical interfaces.

2) Create interface configuration file

you can obtain MAC of the interface from above “ip addr” and it is “00:0C:29:A6:80:73” so HWADDR value is 00:0C:29:A6:80:73 later this value will be added to configuration file. After that you should generate UUID value for the interface from below command.

vim /etc/sysconfig/network-scripts/ifcfg-eth0

below is completed interface config file

3) Activate new interface

🙂

Note :- Linux physical interface name varies. It can be ens192 etc.. particularly VM Ware environment. Most important fact is,  Linux is capable to add multiple IP address to single physical interface by creating virtual interface .

Nov 10

Configure virtual network interface in Centos

Unlike windows, Linux is so flexible in networking. It has lots of built-in networking tools to customize, according  to end user requirement. When look at the Linux virtual interfaces, they are useful for web servers, load balancing servers and proxy servers etc. Here I’m going guide how to configure virtual network interface in Centos ,but other Linux flavors process is similar.

1) Check available physical interfaces

2) Create virtual interface

This example going to create virtual interface for  Linux physical interface called “ens192”

vim /etc/sysconfig/network-scripts/ifcfg-ens192:0

if it is DHCP change boot protocol as below

then save and exit

3) start virtual interface

or

4) Verification

out put will shows newly created virtual interface, just like below

 

Older posts «

» Newer posts

Fetch more items