Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- LOGIN=your@box.com # Your box.com login (email)
- PASS=SomePass # Your box.com password
- LOCALDIR=/home/backups/sites # Local path to backup
- REMOTEDIR=/backups/sites # Remote storage path
- MAXFS=190000000 # Maximum file size allowed without splitting in bytes
- URL=https://www.box.net/dav # WebDAV URL. Leave this for Box.com.
- cd $LOCALDIR
- # Traverse into each directory inside LOCALDIR
- for dirs in *; do
- # Now we need to create same directory on remote, else upload fails
- echo Creating remote $REMOTEDIR/$dirs...
- curl -u $LOGIN:$PASS -X MKCOL $URL$REMOTEDIR/$dirs
- # Now lets work with each file which ends on current date.tar.gz (can change to * for every file)
- for files in $dirs/*-`date +%Y-%m-%d`.tar.gz; do
- # Let's check if file size are less than MAXFS.
- fs=$( stat -c %s $files )
- # If smaller -> upload directly.
- if [ $fs -lt $MAXFS ]; then
- echo Uploading $LOCALDIR/$files...
- curl --user $LOGIN:$PASS -T $files $URL$REMOTEDIR/$files
- # Else we are splitting in into parts by MAXFS bytes then upload them as basename.partnum
- else
- echo $LOCALDIR/$files more than $MAXFS bytes, splitting.
- cnt=0
- # Split file to temporary parts in /tmp. $$ is the current PID, you can do something else.
- split -b $MAXFS $files /tmp/$$.
- for splits in /tmp/$$.*; do
- echo Uploading part $cnt $REMOTEDIR/$dirs/`basename $files`.$cnt
- curl --user $LOGIN:$PASS -T $splits $URL$REMOTEDIR/$dirs/`basename $files`.$cnt
- cnt=$((cnt+1))
- done
- # Clean up temporary parts in /tmp after finishing uploads.
- rm /tmp/$$.*
- fi
- done
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement