Skip to content

Commit 8954d8f

Browse files
authored
AWS Backup Scripts from Jurski NYC
1 parent 5b19711 commit 8954d8f

10 files changed

+1089
-4
lines changed

Diff for: LICENSE

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Apache License
1+
Apache License
22
Version 2.0, January 2004
33
http://www.apache.org/licenses/
44

@@ -198,4 +198,4 @@
198198
distributed under the License is distributed on an "AS IS" BASIS,
199199
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200200
See the License for the specific language governing permissions and
201-
limitations under the License.
201+
limitations under the License.

Diff for: README.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
# Jurski-NYC-AWS-Backup-Scripts
2-
AWS Backup Scripts from Jurski NYC
1+
# Jurski NYC AWS Backup Scripts

Diff for: aws_cli_and_pip_update.sh

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/bash
2+
#Created by Piotr Jurski
3+
#JURSKI NYC - www.jurskinyc.com
4+
#LICENSE Apache License 2.0
5+
#
6+
#READ ME FIRST!
7+
#Do not update with Notepad++ use 'vi' on Putty
8+
#IF ERROR OCCURS when running: (bash: ./backup.sh: /bin/bash^M: bad interpreter: No such file or directory)
9+
#USE "sed -i -e 's/\r$//' aws_cli_and_pip_update.sh" command
10+
11+
#==========================
12+
#AWS EC2 BACKUP PROCESS
13+
#==========================
14+
LOG=backup_aws_pip_update.log
15+
LOGLOCATION=/backup/backup_logs/
16+
17+
if [ ! -d "${LOGLOCATION}" ]
18+
then
19+
mkdir -p ${LOGLOCATION}
20+
fi
21+
22+
#Update PIP and AWS CLI if outdated
23+
echo "INFO: "`TZ=":America/New_York" date +"%Y-%m-%d-%r"`"--Starting the PIP and AWS CLI update ..."| tee --append /backup/backup_logs/${LOG}
24+
pip install --upgrade pip 2>&1 >/dev/null
25+
pip install --upgrade awscli 2>&1 >/dev/null
26+
echo "INFO: "`TZ=":America/New_York" date +"%Y-%m-%d-%r"`"--Update for PIP and AWS CLI has been completed."| tee --append /backup/backup_logs/${LOG}

Diff for: ec2_prod_ami_backup.sh

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/bin/bash
2+
#Created by Piotr Jurski
3+
#JURSKI NYC - www.jurskinyc.com
4+
#LICENSE Apache License 2.0
5+
#
6+
#READ ME FIRST!
7+
#Do not update with Notepad++ use 'vi' on Putty
8+
#IF ERROR OCCURS when running: (bash: ./backup.sh: /bin/bash^M: bad interpreter: No such file or directory)
9+
#USE "sed -i -e 's/\r$//' ec2_prod_ami_backup.sh" command
10+
11+
#Production Server Info (MODIFY SETTINGS HERE)
12+
prod_instance_id=""
13+
prod_volume_01=""
14+
prod_volume_02=""
15+
prod_region=''
16+
17+
#Date
18+
current_date=$(TZ=":America/New_York" date +%Y-%m-%d-%I-%M-%S-%p)
19+
LOG=backup_prod_ami.log
20+
LOGLOCATION=/backup/backup_logs/
21+
22+
#Configurations
23+
prod_image_name="PROD_AMI_${current_date}"
24+
prod_image_description="PROD_SERVER_AMI_IMAGE"
25+
26+
#Tags
27+
prod_tag_ami_name="Key=Name,Value=PROD_AMI_Backup"
28+
prod_tag_date="Key=Date,Value=${current_date}"
29+
30+
#==========================
31+
#AWS EC2 BACKUP PROCESS
32+
#==========================
33+
34+
35+
36+
if ! [ -f ~/.aws/credentials ]
37+
then
38+
echo "ERROR: "`TZ=":America/New_York" date +"%Y-%m-%d-%r"`"--Backup cannot be created because aws authantication is not configured. Please run \"aws configure\" to set up AWS communication." | tee --append /backup/backup_logs/${LOG}
39+
else
40+
if [ ! -d "${LOGLOCATION}" ]
41+
then
42+
mkdir -p ${LOGLOCATION}
43+
fi
44+
#./ec2-automate-backup.sh -v ${prod_volume_01} ${prod_volume_02}
45+
46+
#Create Flat Server AMI
47+
echo "INFO: "`TZ=":America/New_York" date +"%Y-%m-%d-%r"`"--Starting the AMI image creation ..." | tee --append /backup/backup_logs/${LOG}
48+
49+
ami_id=$(aws ec2 create-image --instance-id ${prod_instance_id} --region ${prod_region} --name ${prod_image_name} --description ${prod_image_description} --no-reboot --output text --query ImageId 2>&1)
50+
51+
#Tag the AMI image
52+
aws ec2 create-tags --region ${prod_region} --resources ${ami_id} --tags ${prod_tag_ami_name} ${prod_tag_date}
53+
54+
#Confirmation to the User
55+
echo "INFO: "`TZ=":America/New_York" date +"%Y-%m-%d-%r"`"--AMI image id: "${ami_id}" was created." | tee --append /backup/backup_logs/${LOG}
56+
fi
57+
58+
59+
60+
61+

0 commit comments

Comments
 (0)