Sponsored Content
Full Discussion: Help with rotating files
Top Forums Shell Programming and Scripting Help with rotating files Post 303040839 by Cacializ on Thursday 7th of November 2019 01:40:39 PM
Old 11-07-2019
Help with rotating files

Hello:
I have a script that gets the ACLs of the /home directory and its contents with getfacl and writes them to a file. The script is run by a cron job and I don't want it to rewrite or append to an already existing file. The point of backing permissions up is because I may need to restore them. But I don't want to store every single created file either.

The files don't need to have a specific naming convention. In fact, I took advantage of this: I decided to name the files after the date they were created:
Code:
#!/bin/sh
readonly file="$(date +'%Y-%m-%d')"
getfacl -pR /home > "/var/acl_backups/$file"

This has the advantage that the most recent files are alphabetically greater than older ones, so I thought of putting them in the positional parameters and delete the one I didn't want to preserve. For example, if I wanted to have a maximum of 7 files in the /var/acl_backups directory:
Code:
#!/bin/sh
LC_COLLATE=C set -- [[:digit:]][[:digit:]][[:digit:]][[:digit:]]-[[:digit:]][[:digit:]]-[[:digit:]][[:digit:]]
if [ $# -ge 7 ]
then
    rm -- "$7"
fi

readonly file="$(date +'%Y-%m-%d')"
getfacl -pR /home > "/var/acl_backups/$file"

Changing the locale of LC_COLLATE may be unnecessary, but I decided to change it just to be sure it sorts numbers from 0 to 9.

My question is: is this a reliable way to rotate files? I thought of using logrotate was well, but as far as I know, it would mean that every file would have the same name except for a number at the end. If I ever need to restore them with setfacl having the date in their names is very convenient.

Thanks in advance.

Last edited by Cacializ; 11-07-2019 at 02:57 PM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Rotating a String

Hi folks, I want to rotate a string in Clock or Ani Clock wise. That is If the string is "TAMIL" the out put should be TAMIL AMILT MILTA ILTAM LTAMI TAMIL Please do help. (1 Reply)
Discussion started by: bubeshj
1 Replies

2. Solaris

rotating the syslogd and messages files

Im about to install a sunfreeware program called logrotate which does exactly what it says on the tin....just a quick question ..if its going to rename messages to messages.0 etc do I need to issue a HUP to syslogd after doing this or will the new messages file get created automatically cheers (2 Replies)
Discussion started by: hcclnoodles
2 Replies

3. Shell Programming and Scripting

awk - Rotating an array 90 degrees

Hi All, I have some data (below) that I need to rotate 90 degrees - in other words I want to flip each row into a column. I've found the following code in the book "Effective awk programming" but it doesn't work on my input data. I've used arrays before but I can't make it work... can... (3 Replies)
Discussion started by: pondlife
3 Replies

4. UNIX for Advanced & Expert Users

logrotate isn't rotating files any longer

I have been using logrotate for quite awhile now. Most logs are rotated daily, using /etc/cron.daily. I noticed that the logs in question have not been rotated since April 6, but daily up to that point. I have logrotate in /etc/cron.daily. The basic command is: /usr/sbin/logrotate... (1 Reply)
Discussion started by: manouche
1 Replies

5. Shell Programming and Scripting

Rotating logs in Perl without message loss

(I'm aware log rotation is a common subject, but I tried searching and couldn't find an answer) For some time now, I've been using the Logfile::Rotate module to rotate logs in a log-monitoring script. So far, I haven't experienced any problems, and it works great because I can use it in Linux... (1 Reply)
Discussion started by: w1r3d
1 Replies

6. Solaris

rotating a log yearly

Hi, I am having some troubles using /usr/sbin/logadm to rotate sulog yearly. Can someone please assist with the correct syntax to rotate the sulog yearly? I'd like to maintain up to 3 years of logs. I am on Solaris 10. Thanks, (1 Reply)
Discussion started by: lwif
1 Replies

7. Shell Programming and Scripting

Monitoring specific string or keyword in rotating log files.

Hi there, I like to ask how i shall monitor specific string or keyword in rotating log files. e.g. I have at 10 rotating logfiles. I use the command below to grep the string, but eventually become non functional because the logfile rotates and new logfile is active. tail -f <logfile1> |grep... (1 Reply)
Discussion started by: shtobias
1 Replies

8. Shell Programming and Scripting

Rotating snapshot backup using rsync

I want to take daily backup(11pm) of /var/www to /mnt/bak excluding /var/www/videos and /var/www/old. HOW to implement a rotating snapshot method, so that i can have multiple(say 4) automatically rotating backups. (0 Replies)
Discussion started by: proactiveaditya
0 Replies

9. Red Hat

ip rotating on exim mail server

Hi all, We have the exim mail server configured on cpanel in centos. We have 5 dedicated ip's. So, when i sending mails to client systems, it should be rotate that ip addressees on every 15 minutes. That means Ip rotating. How can i do it. Can anybody show me how to do it. Thanks, (0 Replies)
Discussion started by: mastansaheb
0 Replies

10. Shell Programming and Scripting

Pattern count on rotating logs for the past 1 Hr

Hi All, I have a requirement to write a shell script to search the logs in past 1 hour and extract some pattern from it and count it cumulatively to a file. The problem which I'm facing here is - logs rotates on size basis, say if size of log reaches 5 MB then new log will be generated and... (7 Replies)
Discussion started by: Gem_In_I
7 Replies
VFS_SHADOW_COPY2(8)					    System Administration tools 				       VFS_SHADOW_COPY2(8)

NAME
vfs_shadow_copy2 - Expose snapshots to Windows clients as shadow copies. SYNOPSIS
vfs objects = shadow_copy2 DESCRIPTION
This VFS module is part of the samba(7) suite. The vfs_shadow_copy2 VFS module functionality that is similar to Microsoft Shadow Copy services. When setup properly, this module allows Microsoft Shadow Copy clients to browse "shadow copies" on Samba shares. This is a 2nd implementation of a shadow copy module. This version has the following features: 1. You don't need to populate your shares with symlinks to the snapshots. This can be very important when you have thousands of shares, or use [homes]. 2. The inode number of the files is altered so it is different from the original. This allows the 'restore' button to work without a sharing violation. This module is stackable. CONFIGURATION
vfs_shadow_copy2 relies on a filesystem snapshot implementation. Many common filesystems have native support for this. Filesystem snapshots must be mounted on specially named directories in order to be recognized by vfs_shadow_copy2. The snapshot mount points must be immediate children of a the directory being shared. The snapshot naming convention is @GMT-YYYY.MM.DD-hh.mm.ss, where: o YYYY is the 4 digit year o MM is the 2 digit month o DD is the 2 digit day o hh is the 2 digit hour o mm is the 2 digit minute o ss is the 2 digit second. The vfs_shadow_copy2 snapshot naming convention can be produced with the following date(1) command: TZ=GMT date +@GMT-%Y.%m.%d-%H.%M.%S OPTIONS
shadow:snapdir = SNAPDIR Path to the directory where snapshots are kept. shadow:basedir = BASEDIR Path to the base directory that snapshots are from. shadow:sort = asc/desc, or not specified for unsorted (default) By this parameter one can specify that the shadow copy directories should be sorted before they are sent to the client. This can be beneficial as unix filesystems are usually not listed alphabetically sorted. If enabled, you typically want to specify descending order. shadow:localtime = yes/no This is an optional parameter that indicates whether the snapshot names are in UTC/GMT or in local time. By default UTC is expected. shadow:format = format specification for snapshot names This is an optional parameter that specifies the format specification for the naming of snapshots. The format must be compatible with the conversion specifications recognized by str[fp]time. The default value is "@GMT-%Y.%m.%d-%H.%M.%S". shadow:fixinodes = yes/no If you enable shadow:fixinodes then this module will modify the apparent inode number of files in the snapshot directories using a hash of the files path. This is needed for snapshot systems where the snapshots have the same device:inode number as the original files (such as happens with GPFS snapshots). If you don't set this option then the 'restore' button in the shadow copy UI will fail with a sharing violation. shadow:snapdirseverywhere = yes/no If you enable shadow:snapdirseverywhere then this module will look out for snapshot directories in the current and all parent directories of the current working directory. An example where this is needed are independent filesets in IBM's GPFS, but other filesystems might support snapshotting only particular subtrees of the filesystem as well. EXAMPLES
Add shadow copy support to user home directories: [homes] vfs objects = shadow_copy2 shadow:snapdir = /data/snapshots shadow:basedir = /data/home shadow:sort = desc CAVEATS
This is not a backup, archival, or version control solution. With Samba or Windows servers, vfs_shadow_copy2 is designed to be an end-user tool only. It does not replace or enhance your backup and archival solutions and should in no way be considered as such. Additionally, if you need version control, implement a version control system. VERSION
This man page is correct for version 3.2.7 of the Samba suite. AUTHOR
The original Samba software and related utilities were created by Andrew Tridgell. Samba is now developed by the Samba Team as an Open Source project similar to the way the Linux kernel is developed. Samba 4.0 06/17/2014 VFS_SHADOW_COPY2(8)
All times are GMT -4. The time now is 11:41 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy