Keep only a certain amount of backups (tarballs) in a directory
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
On my debian 9.4 machine I have a script that automatically compresses & backups up all my files in a srv/ with the date in the name xx-xx-xxxx.tar. It is moved to my backups/ directory.
I would like to limit the amount of .tar files (backups) to 10 in the folder, and remove the oldest .tar file every time a new tar is created.
What would be the best way of going about this? Here is my script:
#!/bin/bash
#Purpose = Backup of Important Data
#Created on 17-1-2012
#Author = Hafiz Haider
#Version 1.0
#START
TIME=`date +%b-%d-%y` # This Command will add date in Backup File Na$
FILENAME=backup-$TIME.tar.gz # Here i define Backup file name format.
SRCDIR=/srv/daemon-data # Location of Important Data Directo$
DESDIR=/backups # Destination of backup file.
tar -cpzf $DESDIR/$FILENAME $SRCDIR
#END
scripting backup tar
add a comment |
up vote
0
down vote
favorite
On my debian 9.4 machine I have a script that automatically compresses & backups up all my files in a srv/ with the date in the name xx-xx-xxxx.tar. It is moved to my backups/ directory.
I would like to limit the amount of .tar files (backups) to 10 in the folder, and remove the oldest .tar file every time a new tar is created.
What would be the best way of going about this? Here is my script:
#!/bin/bash
#Purpose = Backup of Important Data
#Created on 17-1-2012
#Author = Hafiz Haider
#Version 1.0
#START
TIME=`date +%b-%d-%y` # This Command will add date in Backup File Na$
FILENAME=backup-$TIME.tar.gz # Here i define Backup file name format.
SRCDIR=/srv/daemon-data # Location of Important Data Directo$
DESDIR=/backups # Destination of backup file.
tar -cpzf $DESDIR/$FILENAME $SRCDIR
#END
scripting backup tar
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
On my debian 9.4 machine I have a script that automatically compresses & backups up all my files in a srv/ with the date in the name xx-xx-xxxx.tar. It is moved to my backups/ directory.
I would like to limit the amount of .tar files (backups) to 10 in the folder, and remove the oldest .tar file every time a new tar is created.
What would be the best way of going about this? Here is my script:
#!/bin/bash
#Purpose = Backup of Important Data
#Created on 17-1-2012
#Author = Hafiz Haider
#Version 1.0
#START
TIME=`date +%b-%d-%y` # This Command will add date in Backup File Na$
FILENAME=backup-$TIME.tar.gz # Here i define Backup file name format.
SRCDIR=/srv/daemon-data # Location of Important Data Directo$
DESDIR=/backups # Destination of backup file.
tar -cpzf $DESDIR/$FILENAME $SRCDIR
#END
scripting backup tar
On my debian 9.4 machine I have a script that automatically compresses & backups up all my files in a srv/ with the date in the name xx-xx-xxxx.tar. It is moved to my backups/ directory.
I would like to limit the amount of .tar files (backups) to 10 in the folder, and remove the oldest .tar file every time a new tar is created.
What would be the best way of going about this? Here is my script:
#!/bin/bash
#Purpose = Backup of Important Data
#Created on 17-1-2012
#Author = Hafiz Haider
#Version 1.0
#START
TIME=`date +%b-%d-%y` # This Command will add date in Backup File Na$
FILENAME=backup-$TIME.tar.gz # Here i define Backup file name format.
SRCDIR=/srv/daemon-data # Location of Important Data Directo$
DESDIR=/backups # Destination of backup file.
tar -cpzf $DESDIR/$FILENAME $SRCDIR
#END
scripting backup tar
scripting backup tar
asked 2 hours ago
coolman5594
172
172
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
0
down vote
accepted
Add the following in the script towards the end:
find "$DESDIR/$FILENAME" -type f -mtime +10 -delete
This will find your backup file (tar.gz) in the directory and delete any backup that is more than 10 days older.
add a comment |
up vote
0
down vote
You want the same logic that is used by the system utility logrotate(8), which can be configured to keep up to a maximum number of files. In user space, there are a number of logrotate-like utilities, as described in this answer: https://superuser.com/a/868519
That being said, a simple configuration file like
"/home/coolman/backups"
rotate 10
should work with the command line
/usr/sbin/logrotate -s $HOME/backups.state -f $HOME/backups.config
New contributor
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
Add the following in the script towards the end:
find "$DESDIR/$FILENAME" -type f -mtime +10 -delete
This will find your backup file (tar.gz) in the directory and delete any backup that is more than 10 days older.
add a comment |
up vote
0
down vote
accepted
Add the following in the script towards the end:
find "$DESDIR/$FILENAME" -type f -mtime +10 -delete
This will find your backup file (tar.gz) in the directory and delete any backup that is more than 10 days older.
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
Add the following in the script towards the end:
find "$DESDIR/$FILENAME" -type f -mtime +10 -delete
This will find your backup file (tar.gz) in the directory and delete any backup that is more than 10 days older.
Add the following in the script towards the end:
find "$DESDIR/$FILENAME" -type f -mtime +10 -delete
This will find your backup file (tar.gz) in the directory and delete any backup that is more than 10 days older.
answered 2 hours ago
sla3k
1864
1864
add a comment |
add a comment |
up vote
0
down vote
You want the same logic that is used by the system utility logrotate(8), which can be configured to keep up to a maximum number of files. In user space, there are a number of logrotate-like utilities, as described in this answer: https://superuser.com/a/868519
That being said, a simple configuration file like
"/home/coolman/backups"
rotate 10
should work with the command line
/usr/sbin/logrotate -s $HOME/backups.state -f $HOME/backups.config
New contributor
add a comment |
up vote
0
down vote
You want the same logic that is used by the system utility logrotate(8), which can be configured to keep up to a maximum number of files. In user space, there are a number of logrotate-like utilities, as described in this answer: https://superuser.com/a/868519
That being said, a simple configuration file like
"/home/coolman/backups"
rotate 10
should work with the command line
/usr/sbin/logrotate -s $HOME/backups.state -f $HOME/backups.config
New contributor
add a comment |
up vote
0
down vote
up vote
0
down vote
You want the same logic that is used by the system utility logrotate(8), which can be configured to keep up to a maximum number of files. In user space, there are a number of logrotate-like utilities, as described in this answer: https://superuser.com/a/868519
That being said, a simple configuration file like
"/home/coolman/backups"
rotate 10
should work with the command line
/usr/sbin/logrotate -s $HOME/backups.state -f $HOME/backups.config
New contributor
You want the same logic that is used by the system utility logrotate(8), which can be configured to keep up to a maximum number of files. In user space, there are a number of logrotate-like utilities, as described in this answer: https://superuser.com/a/868519
That being said, a simple configuration file like
"/home/coolman/backups"
rotate 10
should work with the command line
/usr/sbin/logrotate -s $HOME/backups.state -f $HOME/backups.config
New contributor
New contributor
answered 49 mins ago
djs
1
1
New contributor
New contributor
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f480898%2fkeep-only-a-certain-amount-of-backups-tarballs-in-a-directory%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password