Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
i've been having some fun setting up a vps to host some sites for my friends.
in an effort to back up their sites i'm using cron jobs and grive to tar the site folder and sync it to google drive.
the problem that has come up is that syncing looks for new or different file names and the cron job that tars the site folder saves it with same name each time by overwriting the existing file.
the syntax i use is
tar -cvpzf /site_backups/purpleearth.tar.gz /home/purpleearth/public_html
is there a way to have the tar file saved with a postfix like 01, 02, etc. depending on the existing files in the directory?
The easiest and most descriptive option is to postfix the date instead of a counter. That way not only do you know "3 came after 2", but you know when each backup was actually saved, and you never have to worry about duplicates.
To do that, just change your tar command to:
Code:
tar -cvpzf /site_backups/purpleearth_$(date -u +%Y%m%d_%H%M%S).tar.gz /home/purpleearth/public_html
Of course you can change the format code to whatever you wish, use "man date" for the available options. The "-u" flag uses UTC for the timestamping rather than your current local time.
Two things: don't use "-v" with tar (unless you need to capture and log output) and try to use a backup scheme that provides retention.
Code:
#!/bin/bash --
# Set debug mode when testing:
set -vxe
# Set default behaviour:
LANG=C; LC_ALL=C; export LANG LC_ALL
# Be nice:
which nice >/dev/null 2>&1 && nice -n +20 $$ >/dev/null 2>&1
which ionice >/dev/null 2>&1 && ionice -c3 -n3 -p $$ >/dev/null 2>&1
# This provides retention for a week and only backups newer files during the week:
NOW=$(/bin/date +%a); THEN=$(/bin/date +"%Y-%m-%d" --date="1 day ago")
case "$NOW" in
Sun) # Create full backup:
tar -cpzf "/site_backups/purpleearth-${NOW}.tar.gz" /home/purpleearth/public_html
;;
*) # Create backup relative to yesterday:
tar --newer "$THEN" -cpzf "/site_backups/purpleearth-${NOW}.tar.gz" /home/purpleearth/public_html
;;
esac
# Now rsync stuff and exit
# rsync --whatever-args source dest;
exit 0
i tried suicidaleggrol's suggestion straight-away and it's a good quick fix to where i was at.
thank you. it brought my backup plan together.
i'm really digging grive.
google drive is stable, free, expansive.
for a beginner there were a lot of potential options at first glance.
unspawn, always being the one to take it too the next level,
if i can get my head around it, your suggestion intrigues me.
please to ask a few questions...
- i'm not following the rsync command. i had thought rsync was another option besides grive.
is this a different approach to backing up to google drive you are suggesting?
i'm not following the rsync command. i had thought rsync was another option besides grive.
is this a different approach to backing up to google drive you are suggesting?
No, by all means, if you use grive, keep using that.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.