Last active
July 11, 2019 22:29
-
-
Save stefanbenten/55dc4699fa83549cc00e6ba708f95949 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# USAGE: ./reupload.sh (<BUCKET-ID>) | |
# Bucket-ID is optional, if not provided the entire account is reuploaded | |
passphrase=TEST | |
storage="./files/" | |
bpath=$(pwd) | |
file="./bucket.list" | |
reuploadbucket() { | |
#Get all files in bucket | |
STORJ_KEYPASS=$passphrase ./storj list-files $bucket > $file | |
#Go into directory | |
mkdir $storage/$bucket | |
pushd $storage/$bucket | |
while read line; do | |
read field1 ID field3 SIZE field4 field5 DECRYPTED field6 TYPE field7 CREATEDAT field8 NAME <<< $line | |
#Download File | |
echo $ID $NAME | |
STORJ_KEYPASS=$passphrase $bpath/storj download-file $bucket $ID $NAME | |
#Delete File | |
STORJ_KEYPASS=$passphrase $bpath/storj remove-file $bucket $ID | |
#Upload File | |
echo "Uploading File $NAME" | |
#STORJ_KEYPASS=$passphrase $bpath/storj upload-file $bucket $NAME | |
val="$(STORJ_KEYPASS=$passphrase $bpath/storj upload-file $bucket $NAME)" | |
val2=$(echo "$val" | grep "File ID: ") | |
read f1 f2 f3 f4 NEWID <<< $val2 | |
if [ -z "$NEWID" ] | |
then | |
echo "File Upload failed.." | |
else | |
echo "File Upload successful!" | |
#Log Information | |
echo "ID: $ID Name: $NAME Size: $SIZE -> New ID: $NEWID" >> $bpath/process.log | |
fi | |
done < $file | |
popd | |
} | |
if [ "$1" == "" ] | |
then | |
#Get all buckets and fetch their IDs | |
buckets=$(STORJ_KEYPASS=$passphrase ./storj list-buckets) | |
while read -r line; do | |
#echo $line | |
read f1 BID f3 f4 f5 <<< $line | |
echo "Starting reupload of bucket $BID" | |
bucket=$BID | |
reuploadbucket | |
done < <(printf '%s\n' "$buckets") | |
#echo $buckets | |
else | |
bucket=$1 | |
echo $bucket | |
reuploadbucket | |
fi | |
#Cleanup | |
rm -f $file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Setup:
1.) Download: https://github.com/storj/libstorj/releases/tag/v2.0.0-beta3
2.) Extract the archive.
3.) Go into the bin folder of the newly created folder (eg. libstorj-2.0.0-beta3/bin)
4.) Copy this script into this folder and make it executable
5.) Make sure you are logged into your account by using
./storj list-buckets
6.) Make a folder called files or edit the config value on the top called storage (line 5)
7.) Change the passphrase in line 4
8.) Execute the script by passing in the BucketID which you like to reupload or just leave it blank to reupload everything