Skip to content

Commit

Permalink
put object
Browse files Browse the repository at this point in the history
  • Loading branch information
AvidDabbler committed Feb 5, 2024
1 parent 0f08786 commit 684af12
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
Empty file removed data.db
Empty file.
19 changes: 11 additions & 8 deletions drizzle/backup.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

import cron from 'node-cron';

Check failure on line 2 in drizzle/backup.ts

View workflow job for this annotation

GitHub Actions / ⬣ ESLint

There should be at least one empty line between import groups
import { envConfig } from '~/config.server';

Check failure on line 3 in drizzle/backup.ts

View workflow job for this annotation

GitHub Actions / ⬣ ESLint

There should be at least one empty line between import groups
import { S3Client, CopyObjectCommand } from '@aws-sdk/client-s3'

import { S3Client, PutObjectCommand } from '@aws-sdk/client-s3'

Check failure on line 4 in drizzle/backup.ts

View workflow job for this annotation

GitHub Actions / ⬣ ESLint

There should be at least one empty line between import groups

Check failure on line 4 in drizzle/backup.ts

View workflow job for this annotation

GitHub Actions / ⬣ ESLint

`@aws-sdk/client-s3` import should occur before import of `node-cron`
import fs from 'fs'
const s3Client = new S3Client({
region: "us-east-1", // Replace with your AWS region
credentials: {
Expand All @@ -12,14 +12,17 @@ const s3Client = new S3Client({
});

// Function to perform S3 object copy (backup)
export async function backupS3Object(bucket: string, sourceKey: string, destinationKey: string) {
export async function backupS3Object(bucket: string, filePath: string, destinationKey: string) {
try {
const copyObjectCommand = new CopyObjectCommand({
Bucket: envConfig.S3_BUCKET, // Replace with your S3 bucket name
// CopySource: `/${bucket}/${sourceKey}`, // Source object key
CopySource: `drizzle/${sourceKey}`, // Source object key
Key: destinationKey, // Destination object key
const fileContent = fs.readFileSync(filePath);

// Create S3 PutObjectCommand with the specified prefix
const copyObjectCommand = new PutObjectCommand({
Bucket: bucket,
Key: destinationKey,
Body: fileContent,
});

const response = await s3Client.send(copyObjectCommand);
console.log(`Backup successful. Copy operation response:`, response);
} catch (error) {
Expand Down

0 comments on commit 684af12

Please sign in to comment.