File size: 1,134 Bytes
3187e12
80b07d7
3f1cf03
 
 
e2ecccc
ddc6af5
a15398c
 
 
d390cf1
3f1cf03
03ee9b6
e31bf47
4aab7c2
d390cf1
3f1cf03
 
 
 
 
 
 
 
 
 
 
 
 
 
a6053a0
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import os
import datetime
import boto3
import time
from botocore.exceptions import ClientError
import json

AWS_ACCESS_KEY_ID = os.environ['aws_key']
AWS_SECRET_ACCESS_KEY = os.environ['aws_secret']
BUCKET_NAME = 'app-data-storage-354897'

def upload_to_s3(current_time):
    local_file_path = "/db/rasa/rasa.db" 
    s3_object_key = f'data_{current_time}.db'
  
    try:
        s3 = boto3.client('s3', aws_access_key_id=AWS_ACCESS_KEY_ID, aws_secret_access_key=AWS_SECRET_ACCESS_KEY)
        s3.upload_file(local_file_path, BUCKET_NAME, s3_object_key)
        print(f"Uploaded '{local_file_path}' to '{s3_object_key}' in bucket '{BUCKET_NAME}' at {current_time}")
    except FileNotFoundError:
        print(f"Local file '{local_file_path}' not found at {current_time}")
    except ClientError as e:
        print(f"An error occurred during S3 upload: {e} at {current_time}")

if __name__ == '__main__':
    while True:
        current_time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
        time.sleep(120)
        print("-" * 20)
        upload_to_s3(current_time)
        print("-" * 20)
        time.sleep(12*60*60)