Abdulrahman AlQallaf

Decluttering my mind into the web ...







How to back up Digital Ocean Spaces (S3 compatible storage)

date posted: 2020-Jun-07, last edit date: 2020-Jul-03


Useful resources:

 

STEP 1: In your digital ocean dashboard…

  1. go to account
  2. API
  3. spaces access key
  4. generate new key
  5. save both the access key, and secret key in a text file

STEP 2: Go to your space settings, and add a new entry in the “CORS Configurations” as follows…

  • origin == *
  • allowed methods == GET
  • allowed headers == Access-Control-Allow-Origin

 

STEP 3: Follow the below script on your local machine…

# install required packages
$ sudo apt install s3fs
$ sudo apt install awscli

# store credentials in a file 
# note: file location is important, see man pages for more details
$ echo ACCESSKEY:SECRETKEY > ~/.passwd-s3fs
$ cat ~/.passwd-s3fs

# restrict file permissions
$ chmod 600 ~/.passwd-s3fs
$ ll ~/.passwd-s3fs

# create the location where you want to mount the S3 drive
$ mkdir ~/s3-drive

# mount drive
# note: check that the drive is not already mounted first
$ s3fs -o del_cache -o passwd_file=~/.passwd-s3fs -o use_path_request_style -o url=https://<S3 space name>.<region name>.digitaloceanspaces.com/ <folder name> ~/s3-drive

# check that the drive is mounted
$ mount | grep s3

# step into the drive
$ cd ~/s3-drive

# list all available files
$ aws s3 ls s3://<S3 space name>/ --endpoint=https://<region name>.digitaloceanspaces.com --recursive | less

# copy files needed from bucket to local
$ aws s3 cp s3://<S3 space name>/<path to folder that you want to copy>/ /<local path> --endpoint=https://<region name>.digitaloceanspaces.com --recursive

# unmount drive
fusermount -u ~/s3-drive





# Post Title Date Posted Last Edit Date
1 New tools for data analysis (ipython-sql and Azure Data Studio) 2021-10-16 2021-10-16
2 How to setup a remote jupyter server 2021-10-13 2021-10-13
3 How to setup ZSH 2021-10-12 2021-10-12
4 Concepts in Data Architecture 2021-05-01 2021-10-16
5 Loading data into PostgreSQL reference 2021-03-19 2021-03-19
6 SQLite <--> Pandas reference 2021-03-15 2021-03-15
7 Creating an automated data mart (in SQL) 2020-07-16 2020-07-16
8 Personal finance management and open banking 2020-07-12 2020-07-12
9 Quick SQL reference 2020-07-03 2020-11-29
10 current post -- How to back up Digital Ocean Spaces (S3 compatible storage) 2020-06-07 2020-07-03
11 PostgreSQL initiation 2020-05-25 2020-06-01