46

For a server I am hosting a website on I want to backup the data and settings to an S3 bucket. I found out that you can't directly use rsync to backup to an S3 bucket. Is there another way to achieve the following rsync command to backup the data to an S3 bucket?

rsync -­av ­/Data /s3bucket

I also want to backup the mysql database on that server to the S3 bucket. What is the best way to achieve this?

Last question, if I managed to backup everything to the S3. What is the best way restore the server if it's crashed or in worst case completely wiped? Do I have to note the server settings myself and reconfigure the server or is there a way to also backup this?

Bart Bergmans
  • 583
  • 1
  • 5
  • 9

3 Answers3

53

To communicate to s3 you need to have 2 things

  1. IAM user credentials who has read-write access to s3 bucket.
  2. A client like aws-cli for bash, boto library for Python etc.

once you have both, you can transfer any file from your machine to s3 and from s3 to your machine. Below is the example for aws-cli.

To sync all files in a folder

aws s3 sync source_folder  s3://your_bucket_name/destination_folder/

To copy one file to s3

aws s3 cp source_file s3://your_bucket_name/destination_folder/

Just replace source & destination in the command to download any file from s3.

for more info follow aws docs

Eddie C.
  • 487
  • 1
  • 3
  • 12
Gaurav Pundir
  • 1,376
  • 11
  • 14
  • 2
    Note: you will probably want to run "aws configure" first, in order to store your credentials, so that you don't have to enter them with each sync. – Tim Burch Apr 28 '18 at 01:29
  • 3
    It's worth pointing out that `rsync` computes checksums, client side and server side, and then compares them to accurately decide if a file has changed. Whereas `aws s3 sync` does not - it uses file sizes and timestamps. Someone please correct me if I'm wrong ? – Lqueryvg Mar 08 '19 at 14:38
  • I've also noticed that `aws s3 sync` transfers everything even if the file hasn't changed...where as rsync only transfers what changed. – chovy May 18 '21 at 19:40
30

You can try rclone.

Setup (docs):

rclone config

Sync (docs):

rclone sync /my/local/folder s3service:bucket-name
ki9
  • 1,169
  • 1
  • 10
  • 18
  • 1
    Sounds nice, but can you elaborate what the advantage is over using aws s3 sync ? – Kutzi Aug 02 '19 at 09:30
  • It fulfills OP's requirement of using rsync. I haven't used s3 sync, or rclone with s3, so I don't know any more. – ki9 Aug 04 '19 at 02:01
  • 1
    @Kutzi the main advantages I see (when you want to use s3) are in the case you want to sync between different s3(-like) providers (awscli doesn't allow that). Furthermore, if you use a s3-like service not from AWS (minio, backblaze, digital ocean spaces, etc...), you need to specify the endpoint in the command, instead of declaring it the configuration file (there is an [open issue](https://github.com/aws/aws-cli/issues/1270) for that). – Lucas Basquerotto Sep 02 '20 at 18:53
  • 4
    Also rclone preserves timestamps, while aws s3 sync does not. – Markus Sep 25 '20 at 14:18
3

aws-cli is great for syncing to S3 if you are not interested in permission.

Keep in mind that it does not keep permisión information nor other metadata that the files can have.

It is no well advice in the documentation, and thet you have surprises when restoring.

May be it is not important to sync your collection of music of photos, but it is of crucial importance if you are using it to backups your system.

There is another program s3cmd that keeps this data and can do a similar job. It is slower. But I have not tried it.

I was told that the problem is that you can keep in high costs as in S3 you do not only pay per MB saved, but for requests and rsync makes a lot of them.

Fernando
  • 31
  • 1