开发者

Bash script - splitting .TAR file in smaller parts

th开发者_JAVA百科is 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?


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


To join binary files in windows, use

copy /b parts.. dest

/a is for ASCII text files.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜