Copy recording from "/var/spool/asterisk/recording" to a new file

Hello,

Is there a way to copy a recording from “/var/spool/asterisk/recording” to a new file without using chmod/chwon to set the permissions to this folder? When I try to do the copy I get an error message “”/var/spool/asterisk/recording"): error=13, Permission denied"
(I’m using Asterisk 14 and ARI (ari4java))

Thanks for any help!

Issue the copy from a user that has permission to access the file.

Thank you for replying, but I’m not sure I understood you. I can get the recording I need from the folder as a file but when I try to copy it to a new file I get the permissions error. Can you please explain your answer? :slight_smile:

What do you use to show that you can get it from the folder (directory) as a file? Permission denied could be the result of the user you are using not having execute permission on all directories up to the file, not having read permission on the file, not having execute permission on all the directories up to, but not including the destination directory, not having write and execute permission on the destination directory, or the destination file already existing and not having write permission on that.

In any case, this is not an Asterisk related question; it is purely about the OS.

I do:
new File("/var/spool/asterisk/recording/" + recording.getName() + “.” + recording.getFormat());
and when I do the copy I get this error. I thought that is because of asterisk’s recording folder permissions but I’ll think why I get this error.

Thank you for responding.

@naamag
Who is the owner of the directory /var/spool/asterisk/recording and the files in that directory?
What are the permission flags?
Show
ls -la /var/spool/asterisk/recording
That directory along with all the files should be readable by any user - that is why I am surprised that you are getting this error during read (not write) operations.

I’m running asterisk inside a docker container so when entering asterisk container, the command result is:

[asterisk@71e1fb56fee3 /]$ ls -la /var/spool/asterisk/recording
total 8
drwxr-xr-x 2 asterisk asterisk 4096 Aug 21 08:28 .
drwxr-xr-x 1 asterisk asterisk 4096 Oct 15 06:49 …
[asterisk@71e1fb56fee3 /]$

EDIT: I want to save all recordings in a separate database, that’s a better way to describe it

The file will not be usable until the call ends and Asterisk will not remove it, after a crash, so I’m not clear why you even want to do this.

I want to save all recordings in a separate database, that’s a better way to describe it (edited my response but making sure you it)

How are you initiating the copy?

My guess is that you may be trying to do the copy outside of the Docker virtualisation.

In general, though, this is not an Asterisk issue, it is an OS issue. I don’t believe Asterisk even puts locks on files.

If your recording files are any more than raw samples, Asterisk will not write things like the length of the recorded data until just before closing the file, so any copy made before then will not be playable by standard tools.

Yes, I’m trying to copy it to a new file outside docker, and I’m waiting for the recording to finish before doing that (with ari4java I get a RecordingFinished event )