How to create a backup of your videos in Amazon S3
Create a backup of your videos in Amazon S3
It is always good to have a backup of your videos to be safe against accidental video deletion. Learn how to do it using api.video libraries.
Artem Matinian
October 19, 2023
The world is moving very fast, and although we don’t necessarily notice it, we are surrounded by bits and bytes. From the phone you are reading this article on, to the car you are driving, it is truly amazing how our technology is shaped by these bits and bytes. However, with all that magic, these bits and bytes are just digital items, and in an instance, a software glitch, a simple mistake, or physical harm can swiftly erase them.
That’s why api.video has built a strong infrastructure to make sure that in case of a mishap, the videos and data you’ve uploaded to api.video are safe. We have a disaster recovery plan to ensure you have a sound sleep at night.
Backing up & archiving videos at api.video
However, we also know that sometimes, you may want to make sure that you have your own backups for higher security. Various reasons for keeping these backups could be, to be safe against accidental video deletion or archiving your videos to an object storage.
For that reason, api.video has created a Backup and Cold Storage Library to help you backup or archive videos by sending them to the storage provider of your choice.
Using this library, you can backup or archive your videos into one of the popular storage providers – Google Cloud Storage account, Amazon S3 and Azure Storage.
Now you may ask, what does the script in the library do exactly?
The script will iterate through all the videos you have on your api.video account and send these videos to the provider of your choice. All you have to do is choose the provider, get your api.video API key and the provider’s credentials.
It’s worth mentioning, that the library is open source and you can modify it for your use case, for example, if you would like to delete the videos after backup. What you should know about the library in its current version (v1.0) as we speak:
- All backed-up videos are kept and not deleted
- Pagination of the api.video lists is not supported out of the box, however we plan to add it in the next version
- Incremental backup is not supported. If you run the backup again, it will create duplicate files
You can find all the instructions for the library in our Backup & Cold Storage guides.
Step-by-step guide to create a backup of your videos in Amazon S3
Let’s see how you can create a backup of your videos in api.video to Amazon S3.
Preparation
First and foremost, to start running the script, you will need an api.video account. If you haven’t uploaded videos yet to api.video, and you would like to test, make sure to register your sandbox account here.
Some other things you would need are:
- The api.video API key. You can retrieve the API key through this guide.
- The Amazon S3 credentials.
- Amazon S3 region. You can copy it from the console.
- The api.video Cold Storage script.
- Node.js and npm. You can find the installation instructions here.
- Typescript. You can find the installation instructions here.
Getting started
You can find the guide to get the Amazon S3 Access Key id and Secret Key here.
After you’ve got all the keys and installed node.js, npm, and typescript, you can proceed with cloning the script from GitHub.
Cloning the Cold Storage script
Open your terminal or command line and enter the following commands:
$ git clone https://github.com/apivideo/backup-cold-storage
After the library has been cloned, navigate to the directory:
$ cd back-cold-storage
Setting up the script
Once you are in the library directory, install the dependencies
$ npm install
After the dependencies are installed, we will need to enter the credentials we have copied in the preparation phase.
Edit the .env file and replace the following with the keys you've received from AWS and api.video.
# possible providers: google, aws, azure
PROVIDER = "aws"
# api.video API key from your dashboard
APIVIDEO_API_KEY = "api_video_api_key"
# the name of the bucket on Google Amazon S3 or the container on Azure Storage
SPACE_NAME = "your_bucket_name"
# Amazon S3 credentials
AWS_ACCESS_KEY_ID = "amazon_access_key_id"
AWS_SECRET_ACCESS_KEY = "amazon_secret_key"
AWS_REGION = "s3_bucket_region"
Don’t forget to save the file.
Running the backup
Once you've got all the keys in place in the .env file, it's time to run the script. As we are running the script on TypeScript, we will need to build it first, hence, the first command you need to run in the script folder is:
$ npm run build
After the script was built, it’s time to run it:
$ npm run backup
That’s it!
Now just sit back and relax while we take care of the backup process. The library will take the object of the video, and serve the link to the provider. The time to create the backup will vary depending on the amount of videos you have.