#!/bin/sh source /root/.bash_profile MONTH=`date +%Y%m` TODAY=`date +%Y%m%d` BUCKET_NAME=yourbucket INSTANCE_ID="" if [ ! -f /tmp/instance-id ]; then INSTANCE_ID=`curl -s http://169.254.169.254/latest/meta-data/instance-id` echo -n $INSTANCE_ID > /etc/instance-id else INSTANCE_ID=`cat /etc/instance-id` fi if [ ! -d /tmp/backup-logs ]; then mkdir /tmp/backup-logs fi DEST_DIR=/tmp/backup-logs/${MONTH}/${TODAY}/${INSTANCE_ID} MOUNT_COUNT=`mount -l | grep "/tmp/backup-logs" | wc -l` if [ ${MOUNT_COUNT} -ne 1 ]; then umount -l /tmp/backup-logs > /dev/null 2>&1 s3fs ${BUCKET_NAME} /tmp/backup-logs fi mkdir -p ${DEST_DIR} cp -frpv /file/to/backup ${DEST_DIR}