Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

On Ubuntu, how do you get all timestamps with file backup?

How would that set timestamp from backup file or what is that for? I am trying to be able to set created at times in Linux. X E.
Wait... let me make sure I am understanding what I just read correctly...you are wanting to edit the actual created at timestamp of a file, after you extract it from the tarball?
 
Wait... let me make sure I am understanding what I just read correctly...you are wanting to edit the actual created at timestamp of a file, after you extract it from the tarball?
Just to make sure I am understanding you correctly...if that is your goal, the this would do it
Bash:
touch -t 202301011234.56 filename
where, "202301011234.56" would set the creation date to filename to January 1, 2023 at 12:34:56, in the format YYYYMMDDhhmm[.ss]
 
Just to make sure I am understanding you correctly...if that is your goal, the this would do it
Bash:
touch -t 202301011234.56 filename
where, "202301011234.56" would set the creation date to filename to January 1, 2023 at 12:34:56, in the format YYYYMMDDhhmm[.ss]
you do need root privs for this, so you may need to sudo and run your script
 
Yes I want to set created at time. Also, I am trying for it at system precision so can it be like YYYYMMDDhhmm[.ss].nnnnnn? Like my system has that precision. I understand I need root privileges. Would that work with an already created file? X E.
 
Yes I want to set created at time. Also, I am trying for it at system precision so can it be like YYYYMMDDhhmm[.ss].nnnnnn? Like my system has that precision. I understand I need root privileges. Would that work with an already created file? X E.
Newer versions may have that kind of precision... I would stick with hhmm[.ss] for reliability
 
Could I do like touch -d similarly? That takes a date string and seems like it should be able to handle whatever system precision there is. X E.
 
I am trying for just newer systems and all timestamps restored as accurately as possible. Also, most echo s are just reminders what is what in that last program. X E.
 
I found that Java has a native set all timestamps. Unsure if that touch works on already made things. I guess I will try Java. I know Java so no need to help with this one. I found java.nio and FileTimes. Maybe this will work. X E.
 
https://zzzcode.ai/answer-question?id=e2020a44-0543-44ea-9e3a-a09a37532ee0
That seems to be an answer about created at time.
https://zzzcode.ai/answer-question?id=ce1d7579-bf03-49f7-826d-d963b99a61b2
That seems to be another answer about changed at time. I would prefer if you check these things before I use or try them. Awaiting expert guidance. It is available on all Linux seemingly.
https://zzzcode.ai/answer-question?id=c2dd4867-7e17-46a1-a279-a6894db79053
Anyway, I have like my answer. X E.
 
Now I did, same result. Not Java yet. I am unsure how to do that. Command I used:
sudo touch -d "2022-01-01 10:00:00" /home/norvel/Desktop/propsXE.txt
X E.
 
Last edited:
Clearest nanosecond precision so far. That is created at time.
That is changed time. This is seeming to be a viable thing. I would have to get inode of restored file and use it. Now just formatting for debugfs command. Also, I like having files without group or owner so I can use it on anything. I know I would have to format a USB to ext4 to use this on that USB. X E.
 
I have what I think should be a working program for restore now. Here it is.
Bash:
#!/bin/bash
if ! command -v touch &> /dev/null; then
    echo "Need 'touch' command. X E."
    exit 1
fi
#12/28/2023, 9:26PM, start, X E. 9:55PM, done for today. X E. 9:59PM, like done for today, X E.
# Specify the file path
file_path="$(pwd)/propsXE.txt"
#12/30/2023, 4:19PM, started work today.
echo "input directory inside origin to restore from"
read origin
if [ -z "$origin" ]; then
    origin=""
fi
echo "input directory to move to"
read dest
if [ -z "$dest" ]; then
    dest=""
fi
if [[ "$dest" != */ ]]; then
    dest="$dest/"
fi
echo "input device to move to path, e.g. /dev/sda1."
read device
if [ -z "$device" ]; then
    device=""
fi
#Check if device exists
if [ ! -b "$device" ]; then
    echo "device does not exist. X E."
    exit 1
fi
# Check if the file exists
if [ -f "$file_path" ]; then
    # Open the file for reading
    exec 3< "$file_path"
    index=0;
    result="";
    change="";
    access="";
    inode=0;
    formatted_time="";
    # Read each line of the file
    while IFS= read -r line <&3; do
        if [ $index -eq 0 ]; then
            if [[ -n $origin ]]; then
                result="${line##$origin}"
            else
                result=$line;
            fi
            if [[ "$result" == /* ]]; then
                result="$dest${result##/}";
            else
                result="$dest$result";
            fi
            if [ ! -f $result ]; then
                if [ $line -ne "X E." ]; then
                    echo "Error $result does not exist."
                fi
            else
                inode=$(stat -c "%i" "$line")
            fi
        elif [ $index -ne 9 ] && [ -f $result ]; then
            if [ $index -eq 1 ]; then
                # Format time
                formatted_time=$(date -d "$line" +%s.%N)
                # Run debugfs command
                debugfs -w -R 'set_inode_field $inode crtime $formatted_time' $device
                #echo "created"
            elif [ $index -eq 2 ]; then
                touch -m -t "$line" "$result"
                #echo "last modified"
            elif [ $index -eq 3 ]; then
                #echo "last access"
                touch -a -t "$line" "$result"
            elif [ $index -eq 4 ]; then
                #echo "change"
                # Format time
                formatted_time=$(date -d "$line" +%s.%N)
                # Run debugfs command
                debugfs -w -R 'set_inode_field $inode ctime $formatted_time' $device
            elif [ $index -eq 5 ]; then
                #echo "permissions"
                chmod $line $result
            elif [ $index -eq 6 ]; then
                #echo "owner"
                chown $line $result
            elif [ $index -eq 7 ]; then
                #echo "group"
                chgrp $line $result
            #else
                #echo "inode $line"
            fi
        fi
        # Process the line
        index=$((index+1));
        if [ $index -eq 10 ]; then
            #touch -a -t "$change" "$result"
            #touch -a -t "$access" "$result"
            index=0;
       fi
    done
  # Close the file
  exec 3<&-
else
  echo "File not found: $file_path"
fi
echo "Done. X E."
#X E.
Now just if I have approval to open source this from @Antero360. Maybe I will let that recursive getter and that not recursive getter both be as not recursive may be a RAM hog and take more RAM than allowed on larger storages. Maybe I should figure how to open source or like that an ext4 USB or an NTFS USB for that matter. Maybe I should just use rsync to have owner be public with chmod option. With that I like have a way to have a full copy of all of a drive and have it open to all including Windows. I think I will continue using NTFS USBs for backup now that I like have this.

I also guess I should ask @Malcolm if I can post this code on a thread shared with community. Thanks @Antero360, zzzcode.ai, and @Malcolm for making this site. I am like done now. X E.
 
Important note about getter of attributes, it does not handle directories pointing to same directory correctly so do not run for everything and as root forever, some loops may occur and running forever like that may destroy your computer. X E.
 
I have been trying to use "find" command to get all things found. No success. Here are like my tries as comments.
Bash:
function startXE() {
    if [ -f "$1propsXE.txt" ]; then
        echo "$1propsXE.txt exists";
        rm -i "$1propsXE.txt";
        if [ -f "$1propsXE.txt" ]; then
            return;
        else
            echo "File deleted";
        fi
    else
        echo "$1propsXE.txt does not exist";
    fi
    tester="$1propsXE.txt";
    #export -f writeXE;
    #find $1 -mindepth 1 -not -path '*/\.*' -exec bash -c ''writeXE' $0 '$tester'' {} \;
    #find $1 -mindepth 0 -exec bash -c "writeXE {} $tester" \;
    #find $1 -mindepth 0 -exec bash -c "writeXE {} $tester" \;
    #find $1 -mindepth 0 -exec bash -c 'writeXE "$0" "$1"' {} "$tester" \;
    echo "X E." >> "$1propsXE.txt";
    echo "Done. X E.";
    #X E.
}
writeXE is either not found or cannot use local variables. What can I do? Goal is to have all recursively inside a folder found and with writeXE called on it. X E.
 

New Threads

Latest posts

Buy us a coffee!

Back
Top Bottom