Follow

Can someone script something for me real quick in bash. This cold and fever and meds has my head all messed up but I want to get linuxrocks backups running again.

if backup-1.tar.gz exist then backup-2.tar.gz

if -1 and -2 exist then backup-1.tar.gz

tar -czvf /home/backups/backup-$n.tar.gz /home/mastodon/live/public/

the script I tried don't seem to wanna work basically I just want two copies of public folder. So simple yet cant seem to think clearly to get it to work

@omnipotens

From your description, that would be

n=1
test -f backup-1.tar.gz || n=2

but I'm pretty sure I'm misinterpreting your request.

@ben

Let me see if I can explain

FILE=backup-1.tar.gz
if [ -f $FILE ]; then
tar -czvf /home/backups/backup-2.tar.gz /home/mastodon/live/public/"
else
if [ -f $FILE ]; then
tar -czvf /home/backups/backup-1.tar.gz /home/mastodon/live/public/"
fi
fi

@ben start over at 1 I only want 2 files. Feel stupid that I cant figure this out. sucks being sick

@omnipotens

how about instead of 1 and 2, it's current and previous

that way, you'd do

mv -f /home/backups/backup-current.tar.gz /home/backups/backup-previous.tar.gz

tar -czvf /home/backups/backup-current.tar.gz /home/mastodon/live/public/

No ifs required.

@ben du damn got it lol thanks I cant beleive I fighting with this lol

Sign in to participate in the conversation
LinuxRocks.Online

Linux Geeks doing what Linux Geeks do..