S3: Sync only files within folders with specific filenames.

1

Hi,

I have on my root server a directory with sql dumps (created once a day and rotating every 7 days)

Example folder structure:

2022-06-27/db_name_1/db_name_1-2022-06-27-22-35.sql.gz
                     /db_name_2/db_name_2-2022-06-27-22-35.sql.gz
                     /db_name_3/db_name_3-2022-06-27-22-35.sql.gz
2022-06-28/db_name_1/db_name_1-2022-06-28-22-35.sql.gz
                     /db_name_2/db_name_2-2022-06-28-22-35.sql.gz
                     /db_name_3/db_name_3-2022-06-28-22-35.sql.gz
2022-06-29/db_name_1/db_name_1-2022-06-29-22-35.sql.gz
                     /db_name_2/db_name_2-2022-06-29-22-35.sql.gz
                     /db_name_3/db_name_3-2022-06-29-22-35.sql.gz

I my case I would like only to backup db_name_1.

So in my S3 bucket I would like to have only the sql dumps of the db_name_1

...
db_name_1-2022-06-27-22-35.sql.gz
db_name_1-2022-06-28-22-35.sql.gz
db_name_1-2022-06-29-22-35.sql.gz
...

So basically I would like to tell aws cli to just look at db_name_1-*.sql.gz

Is this possible?

已提問 2 年前檢視次數 3638 次
1 個回答
1

Kindly first refer to the use of include & exclude filters as referred in link below... https://docs.aws.amazon.com/cli/latest/reference/s3/index.html#use-of-exclude-and-include-filters

Not sure if formatting is showing the folder structure is showing up correctly, but if it is like following ..

2022-06-27/db_name_1/db_name_1-2022-06-27-22-35.sql.gz
2022-06-27/db_name_2/db_name_2-2022-06-27-22-35.sql.gz
2022-06-27/db_name_3/db_name_3-2022-06-27-22-35.sql.gz
2022-06-28/db_name_1/db_name_1-2022-06-28-22-35.sql.gz
2022-06-28/db_name_2/db_name_2-2022-06-28-22-35.sql.gz
2022-06-28/db_name_3/db_name_3-2022-06-28-22-35.sql.gz

then you can try this

aws s3 cp . s3://<your_target_bucket_name/<prefix>/ --recursive --exclude "*" --include "*/db_name_1/db_name_*.sql.gz"

You can try with specific database name as above or asterick if you want them all. As always try with small set of files to test the code to meet your needs.

AWS
已回答 2 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南