Mark S
Mark S

Reputation: 1

Bash script - splitting .TAR file in smaller parts

this a part of a .sh script I need to edit to make some backups and upload them on Dropbox but I need to split that backup in smaller parts.

NOW=$(date +"%Y.%m.%d")
DESTFILE="$BACKUP_DST/$NOW.tgz"

# Backup mysql.
mysqldump -u $MYSQL_USER -h $MYSQL_SERVER -p$MYSQL_PASS --all-databases > "$NOW-Databases.sql"
tar cfz "$DESTFILE" "$NOW-Databases.sql"

And then the function to upload the backup on DropBox....

dropboxUpload "$DESTFILE"

How can I split the .tar file in smaller parts (for example of 100 or 200mb size) and get the name and the number of those files to upload them with the dropboxUpload function?

Upvotes: 0

Views: 560

Answers (2)

fredrik
fredrik

Reputation: 521

To join binary files in windows, use

copy /b parts.. dest

/a is for ASCII text files.

Upvotes: 0

mu is too short
mu is too short

Reputation: 434775

You could use split. For example, this:

split -b500k $DESTFILE ${DESTFILE}-

will split $DESTFILE into 500 KB pieces called:

${DESTFILE}-aa
${DESTFILE}-ab
${DESTFILE}-ac
...

Then you could loop through them with something like:

for x in ${DESTFILE}-*
do
    dropboxUpload $x
end

Upvotes: 2

Related Questions