npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

backup-s3

v1.0.4

Published

The simplest way to backup a file to S3.

Downloads

12

Readme

backup-s3

The simplest way to backup a file to S3.

Sometimes you just want to back something up with minimal configuration. No retained backups, nothing fancy, just a backup that's not on the same server. I think this might be the easiest solution I've seen. And it is super cheap, possibly free! S3's free tier gives you 5GB of data and 15GB of transfer for free. After that, pricing is still very cheap. It can be even cheaper if you choose Reduced Redundancy Storage, but I wouldn't recommend that for a backup.

First, log into AWS and create an S3 Bucket. Remember the name of the bucket. You can choose Reduced Redundancy Storage at this point.

Next, make sure you have your AWS credentials set up. See the AWS documentation for this. You'll need to use the ~/.aws/credentials file approach. Make sure the [default] header is set to the same account you created the S3 bucket with.

Next, install this package. You can do this on your local machine or the machine you're backing up. You must have the AWS credentials on the machine you use to generate the URL.

npm install -g backup-s3

You can then generate an upload and download URL like this:

backup-s3 $BUCKET_NAME $FILENAME

You should get some output like this:

You can upload to this URL like this:

    curl "https://s3.amazonaws.com/$BUCKET_NAME/$FILENAME?AWSAccessKeyId=SOME_KEY&Expires=1830442652&Signature=SOME_SIGNATURE" --upload-file FILENAME

You can then download the file like this:

    curl -o FILENAME "https://s3.amazonaws.com/$BUCKET_NAME/$FILENAME?AWSAccessKeyId=SOME_KEY&Expires=1830442652&Signature=ANOTHER_SIGNATURE"

Now, on the machine you want to backup, create a file backup.sh. In my case, the file was at /home/ubuntu/backup.sh.

#!/bin/bash

# Create an archive of the folder we want to backup (in this game, the game Starbound, which is a ton of fun).
tar czvf /home/ubuntu/starbound.tar.gz /home/ubuntu/starbound_game

# Now we save the file to S3. Make sure the URL is in quotes like below!
curl "THE URL POSTED ABOVE" --upload-file /home/ubuntu/starbound.tar.gz

Now we're going to create a cronjob to do this nightly. The 9 hour in UTC translates to 3am in Central time when it isn't daylight savings time.

crontab -e

# Add this to the bottom and the exit the editor. Adjust the path for where you saved your script.
0 9 * * * bash /home/ubuntu/backup.sh

And that's it!